-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
83 lines (81 loc) · 2.3 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
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
75
76
77
78
79
80
81
82
83
<?php
/*
$postdata = file_get_contents('php://input');
$fp = fopen('./upload/' . $_GET['filename'], 'wb');
fwrite($fp, $postdata);
fclose($fp);
echo 'upload success.'
*/
?>
<?php
/*
* Author: Rohit Kumar
* Date: 12-08-2014
* Website: iamrohit.in
* App Name: Ajax file uploader
* Description: PHP + Ajax file uploader with progress bar
*/
error_reporting(0);
if (($_POST['del'] == 1) && (isset($_POST['del']))) {
if (file_exists($_POST['filePath'])) {
unlink($_POST['filePath']);
$data = json_encode(array(
'type' => 'success',
'msg' => 'File deleted successfully.'
));
} else {
$data = json_encode(array(
'type' => 'error',
'msg' => 'Can not delete, File not exist.'
));
}
echo $data;
exit;
} else {
$allowFile = array(
'image/png',
'image/jpeg',
'image/gif',
'image/jpg'
);
$fileName = $_FILES["file"]["name"]; // iconv("gbk", "UTF-8", $_FILES["file"]["name"]);
// echo $fileName;
if (empty($fileName)) {
echo $data = json_encode(array(
'type' => 'error',
'msg' => "Please choose file to upload."
));
exit;
}
if (in_array($_FILES["file"]["type"], $allowFile)) {
if ($_FILES["file"]["error"] > 0) {
$data = json_encode(array(
'type' => 'error',
'msg' => "Return Code: " . $_FILES["file"]["error"]
));
} else {
$fileName = iconv("UTF-8", "gbk", $fileName);
// echo iconv("UTF-8", "big5", $fileName);
if (file_exists("upload/" . $fileName)) {
$data = json_encode(array(
'type' => 'error',
'msg' => $fileName . " already exists. "
));
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $fileName);
$data = json_encode(array(
'fileName' => $fileName,
'msg' => $fileName . " uploaded successfully.",
'type' => 'success'
));
}
}
} else {
$data = json_encode(array(
'type' => 'error',
'msg' => "Oh! Oh! Oh! Bad file type."
));
}
echo $data;
}
?>