时间:2021-07-01 10:21:17 帮助过:21人阅读
文件大小不能超过2M"; } } ?>
2*1024*1024){ echo "文件过大,不能上传超过2M的文件
"; echo "返回重新上传"; exit(); } $file_type = $_FILES['myfile']['type']; if($file_type != "image/jpg" && $file_type != "image/pjpeg"){ echo "文件类型只能是jpg的"; exit(); } // echo ""; // print_r($_FILES); // echo ""; if(is_uploaded_file($_FILES['myfile']['tmp_name'])){ //把文件转存到你希望的目录; $upLoaded_file = $_FILES['myfile']['tmp_name']; $fileName = $_FILES['myfile']['name']; //给每个用户动态的创建一个文件夹 $user_path = $_SERVER['DOCUMENT_ROOT']."/fileOpt/upLoadFiles/".$username; if(!file_exists($user_path)){ mkdir($user_path); } //$destPath = $user_path."/".$fileName; $destPath = $user_path."/".(time().rand(0,1000)).substr($fileName,strrpos($fileName, ".")); //如果目标文件存在,则被覆盖 if(move_uploaded_file($upLoaded_file,$destPath)){ echo $_FILES['myfile']['name']." 上传成功!"; }else{ echo "上传失败!
"; echo "返回重新上传"; } }else{ echo "上传失败!
"; echo "返回重新上传"; } ?>
以上就介绍了php 上传文件,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。