-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.php
More file actions
52 lines (50 loc) · 1.56 KB
/
upload.php
File metadata and controls
52 lines (50 loc) · 1.56 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
<?php
if ($_FILES['csv']['error'] == 0 && pathinfo($_FILES['csv']['name'], PATHINFO_EXTENSION) === 'csv') {
$tmpName = $_FILES['csv']['tmp_name'];
$totalArr = [];
if (($handle = fopen($tmpName, 'r')) !== FALSE) {
$fArray = [];
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// Process each row of data here
if(isset($_POST['objectiv'])){
$obj = htmlspecialchars($_POST['objectiv']);
array_push($totalArr , $data[58]);
// print_r($data[8]);
// echo '<br>';
}
$finalArr = totalArrClear($totalArr , $obj);
// print_r($finalArr);
for($i = 0 ; $i < count($finalArr) ; $i++){
$data[8] = $finalArr[$i];
}
array_push($fArray , $data);
}
// print_r($fArray);
putDataInCsvFile($fArray);
fclose($handle);
}
$totalArr[0] = 'توضیحات';
// print_r($totalArr);
}
function totalArrClear($arr , $obj){
$arr[0] = 'توضیحات';
for($i = 1 ; $i < count($arr) ; $i++){
$arr[$i] = 'سایز:' . $arr[$i] . $obj;
}
return $arr;
}
function putDataInCsvFile($data){
$filename = 'test.csv';
// Open CSV file for writing
$f = fopen($filename, 'w');
if ($f === false) {
die('Error opening the file ' . $filename);
}
// Write each row at a time to a file
foreach ($data as $row) {
fputcsv($f, $row);
}
// Close the file
fclose($f);
echo '<a href="test.csv">فایل</a>';
}