-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_pic.php
75 lines (61 loc) · 1.98 KB
/
upload_pic.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
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<form action="" enctype="multipart/form-data" method="post"
name="uploadfile">上传文件:<input type="file" name="upfile" /><br>
<input type="submit" value="上传" /></form>
<?php
//print_r($_FILES["upfile"]);
if(@is_uploaded_file($_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
//获取数组里面的值
$name=$upfile["name"];//上传文件的文件名
$type=$upfile["type"];//上传文件的类型
$size=$upfile["size"];//上传文件的大小
$tmp_name=$upfile["tmp_name"];//上传文件的临时存放路径
//判断是否为图片
switch ($type){
case 'image/pjpeg':$okType=true;
break;
case 'image/jpeg':$okType=true;
break;
case 'image/gif':$okType=true;
break;
case 'image/png':$okType=true;
break;
}
$uploaded_ext = substr($name, strrpos($name, '.') + 1);
if(@$okType){
/**
* 0:文件上传成功<br/>
* 1:超过了文件大小,在php.ini文件中设置<br/>
* 2:超过了文件的大小MAX_FILE_SIZE选项指定的值<br/>
* 3:文件只有部分被上传<br/>
* 4:没有文件被上传<br/>
* 5:上传文件大小为0
*/
$error=$upfile["error"];//上传后系统返回的值
echo "上传成功,";
echo "上传文件大小是:".$size."<br/>";
//把上传的临时文件移动到up目录下面
//上传后缀名判断,以及可以大小限制
if ($uploaded_ext == "jpg" || $uploaded_ext == "JPG" || $uploaded_ext == "jpeg" || $uploaded_ext == "JPEG" ){
move_uploaded_file($tmp_name,'up/pic/'.$name);
$destination="up/pic/".$name;
if($error==0){
echo "<br>图片预览:<br>";
echo "<img src=".$destination.">";
//echo " alt=\"图片预览:\r文件名:".$destination."\r上传时间:\">";
}elseif ($error==1){
echo "超过了文件大小,在php.ini文件中设置";
}elseif ($error==2){
echo "超过了文件的大小MAX_FILE_SIZE选项指定的值";
}elseif ($error==3){
echo "文件只有部分被上传";
}elseif ($error==4){
echo "没有文件被上传";
}else{
echo "上传文件大小为0";
}
}
}
}
?>