-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.php
32 lines (31 loc) · 1.03 KB
/
upload.php
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
<?php
$output_dir = "uploads/";
if(isset($_FILES["myfile"])) {
$ret = array();
// This is for custom errors;
/* $custom_error= array();
$custom_error['jquery-upload-file-error']="File already exists";
echo json_encode($custom_error);
die();
*/
$error =$_FILES["myfile"]["error"];
$thisTS = time();
//You need to handle both cases
//If Any browser does not support serializing of multiple files using FormData()
if(!is_array($_FILES["myfile"]["name"])) { //single file
$fileName = $_FILES["myfile"]["name"];
#move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$fileName);
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$thisTS.".pdf");
#$ret[]= $fileName;
$ret[]= $thisTS.".pdf";
} else { //Multiple files, file[]
$fileCount = count($_FILES["myfile"]["name"]);
for($i=0; $i < $fileCount; $i++) {
$fileName = $_FILES["myfile"]["name"][$i];
move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName);
$ret[]= $fileName;
}
}
echo json_encode($ret);
}
?>