6.27 上传文件
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> </head> <body> <form action="upfilechuli.php" method="post" enctype="multipart/form-data"> <input type="file" name="upfile" id="upfile" value="" /> <input type="submit" value="上传"/> </form> </body> </html>
<?php //var_dump($_FILES['upfile']); $name = $_FILES['upfile']['name']; $type = $_FILES['upfile']['type']; $tmp_name = $_FILES['upfile']['tmp_name']; $error = $_FILES['upfile']['error']; $size = $_FILES['upfile']['size']; if(!empty($name)){ if($error==0){ if($type=="image/jpeg"){ if($size <=100000){ if(!is_dir("./upfile/")){//判断目录存在与否 mkdir("./upfile/");//创建目录 } $time = time(); $path ="./upfile/".$time.$name; //move_uploaded_file() 函数将上传的文件移动到新位置。 //move_uploaded_file(file,newloc) if(move_uploaded_file($tmp_name,$path)){ echo "上传文件成功"; }else{ echo "上传文件失败"; } }else{ echo "上传文件过大"; } }else{ echo "上传文件格式不对"; } }else{ switch($error){ case 1:echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值"; case 2:echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值"; case 3:echo "文件只有部分被上传"; case 4:echo "没有文件被上传"; } } } else{ echo "上传文件为空"; } ?>