-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsizes.php
More file actions
74 lines (64 loc) · 2.32 KB
/
sizes.php
File metadata and controls
74 lines (64 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
header('Content-Type: text/html; charset=utf-8');
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
if(!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ',', $enclosure = '"') {
if( ! preg_match("/[$enclosure]/", $input) ) {
return (array)preg_replace(array("/^\\s*/", "/\\s*$/"), '', explode($delimiter, $input));
}
$token = "##"; $token2 = "::";
//alternate tokens "\034\034", "\035\035", "%%";
$t1 = preg_replace(array("/\\\[$enclosure]/", "/$enclosure{2}/",
"/[$enclosure]\\s*[$delimiter]\\s*[$enclosure]\\s*/", "/\\s*[$enclosure]\\s*/"),
array($token2, $token2, $token, $token), trim(trim(trim($input), $enclosure)));
$a = explode($token, $t1);
foreach($a as $k=>$v) {
if ( preg_match("/^{$delimiter}/", $v) || preg_match("/{$delimiter}$/", $v) ) {
$a[$k] = trim($v, $delimiter); $a[$k] = preg_replace("/$delimiter/", "$token", $a[$k]); }
}
$a = explode($token, implode($token, $a));
return (array)preg_replace(array("/^\\s/", "/\\s$/", "/$token2/"), array('', '', $enclosure), $a);
}
}
$csv = @$_FILES['csv'];
foreach ($csv['tmp_name'] as $kkey => $tmp) {
// if ($csv['type'][$kkey] != 'text/csv') {
// print $csv['name'][$kkey].' - не удалось сконвертировать. Не CSV.<br/>';
// continue;
// }
$code = file_get_contents($tmp);
$code = str_getcsv($code,"\n");
foreach ($code as $key => $str) {
if ($key == 0)
continue;
$str = str_getcsv($str,';');
$temp = explode('/',$str[7]);
if (count($temp) > 1) {
foreach ($temp as $tkey => $val) {
$str[7] = $val;
if ($tkey == 0) {
$code[$key] = implode(';',$str);
} else {
$code[] = implode(';',$str);
}
}
}
$temp2 = explode('/',$str[9]);
if (count($temp2) > 1) {
foreach ($temp2 as $tkey2 => $val2) {
$str[9] = $val2;
if ($tkey2 == 0) {
$code[$key] = implode(';',$str);
} else {
$code[] = implode(';',$str);
}
}
}
}
$code = implode("\n",$code);
file_put_contents('sizes/'.$csv['name'][$kkey],$code);
print '<h1>ОК, все файлы в папке "sizes"</h1>';
}
?>