1 <?php
 2 header("Content-type: text/html; charset=utf-8");
 3 if (isset($_POST['token'])&&$_POST['token']=='upload') {
 4     // echo "正确提交";
 5     // print_r($_FILES);
 6     // die();
 7     // echo "<br>";
 8     // $_POST[''];
 9     //判断是否出错
10     if ($_FILES['uploadFile']['error']!=0) {
11         echo "<h2>文件上传出错!</h2>";
12         die();
13     }
14     //判断文件是否超出限制
15     if ($_FILES['uploadFile']['size']>=2*1024*1024) {
16         echo "<h2>文件大于2M!</h2>";
17         die();
18     }
19     //判断文件类型是否图像
20     $type = $_FILES['uploadFile']['type'];
21     $arr = array('image/jpeg','image/png','image/gif','image/webp'); 
22     if (!in_array($type,$arr)) {
23         echo '不是图像!';
24         die();
25     }
26     //另存文件到upload文件夹
27     $tmp_name = $_FILES['uploadFile']['tmp_name'];
28     $ext = pathinfo($_FILES['uploadFile']['name'],PATHINFO_EXTENSION);
29     $dst_name = "./upload/".uniqid().'.'.$ext  ;
30     // echo $dst_name;
31     // die();
32     // $dst_name = './upload/'.date('YmdHis').substr($str,stripos($str,'.'),strlen($str)-stripos($str,'.'));
33     move_uploaded_file($tmp_name,$dst_name);
34     // echo $d;
35     print_r($_FILES);
36 }
37 else{
38     echo "非法提交";
39 }

 

版权声明:本文为paoPaoLong_liu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/hnqyliu/p/16609881.html