
注意从test.html 上传到test1.php 需要先建立upload文件夹test.html代码!DOCTYPE htmlhtmlheadmeta charsetUTF-8titleFile Upload Form/title/headform actiontest1.php methodpost enctypemultipart/form-datah2Upload File/h2label forfileSelectFilename:/labelinput typefile namephoto idfileSelectinput typesubmit namesubmit valueUploadpstrongNote:/strong仅允许.jpg、.jpeg、.gif、.png格式最大大小为5 MB。/p/form/htmltest1.php代码?php//检查表单是否已提交if($_SERVER[REQUEST_METHOD] POST){// 检查文件是否上传成功if(isset($_FILES[photo]) $_FILES[photo][error] 0){$allowed array(jpg image/jpg, jpeg image/jpeg, gif image/gif, png image/png);$filename $_FILES[photo][name];$filetype $_FILES[photo][type];$filesize $_FILES[photo][size];// 验证文件扩展名$ext pathinfo($filename, PATHINFO_EXTENSION);if(!array_key_exists($ext, $allowed)) die(错误请选择有效的文件格式。);// 验证文件大小-最大5MB$maxsize 5 * 1024 * 1024;if($filesize $maxsize) die(错误文件大小大于允许的限制。);// 验证文件的MIME类型if(in_array($filetype, $allowed)){// Check whether file exists before uploading itif(file_exists(upload/ . $filename)){echo $filename . is already exists.;} else{move_uploaded_file($_FILES[photo][tmp_name], upload/ . $filename);echo 您的文件已成功上传。;}} else{echo 错误上载您的文件时出现问题。 请再试一次。;}} else{echo Error: . $_FILES[photo][error];}}?