-
Notifications
You must be signed in to change notification settings - Fork 11
/
upload.php
77 lines (71 loc) · 1.9 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
<?php
/*
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
*/
#if (($_FILES["myfile"]["name"] != "")&&($_FILES["myfile"]["size"] < 50000000))
if ($_FILES["myfile"]["name"] != "")
{
if ($_FILES["myfile"]["error"] > 0)
{
echo "Return Code: " . $_FILES["myfile"]["error"] . "<br />";
/*
switch ($_FILES["myfile"]["error"])
{
case 1:
echo "文件大小超过了PHP.ini中的文件限制!";
break;
case 2:
echo "文件大小超过了浏览器限制!";
break;
case 3:
echo "文件部分被上传!";
break;
case 4:
echo "没有找到要上传的文件!";
break;
case 5:
echo "服务器临时文件夹丢失,请重新上传!";
break;
case 6:
echo "文件写入到临时文件夹出错!";
break;
}
*/
}
else
{
/*
echo "Upload: " . $_FILES["myfile"]["name"] . "<br />";
echo "Type: " . $_FILES["myfile"]["type"] . "<br />";
echo "Size: " . ($_FILES["myfile"]["size"] / (1024*1024)) . " MB<br />";
echo "Temp file: " . $_FILES["myfile"]["tmp_name"] . "<br />";
*/
if (file_exists("./upload/" . $_FILES["myfile"]["name"]))
{
echo "<script language='javascript'>";
echo "alert('".$_FILES["myfile"]["name"]." already exists! ');";
echo "window.location='upload.html';";
echo "</script>";
}
else
{
echo "Upload: " . $_FILES["myfile"]["name"] . "<br />";
echo "Type: " . $_FILES["myfile"]["type"] . "<br />";
echo "Size: " . ($_FILES["myfile"]["size"] / (1024*1024)) . " MB<br />";
move_uploaded_file($_FILES["myfile"]["tmp_name"],
"./upload/" . $_FILES["myfile"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["myfile"]["name"];
}
}
}
else
{
echo "<script language='javascript'>";
echo "alert('Invalid file! ');";
echo "window.location='upload.html';";
echo "</script>";
}
?>