Heim > Fragen und Antworten > Hauptteil
Notice: /a/upload.php line 5 - Undefined index: m
Notice: /a/upload.php line 18 - Undefined index: m
Debug Strict (PHP 5): /a/upload.php line 18 - Only variables should be passed by reference
upload.html
<!DOCTYPE html> <html> <head> <title>文件上传</title> </head> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000"> 选择文件:<input type="file" name="m"><br> <input type="submit" value="上传文件"> </form> </body> </html>
upload.php
<?php $allowtype=array("text","doc","php","html"); $size=1000000; if($_FILES['m']['error']>0) { echo "Error: <br />"; switch ($_FILES['m']['error']) { case 1: die('上传文件大小超过php文件约定值'); case 2: die('上传文件大小超过表单约定值'); case 3:die('文件部分上传'); case 4: die('没有上传文件'); default:die('未知错误'); } } $hz=array_pop(explode(".",$_FILES['m']['name'] )); if(!in_array($hz, $allowtype)){ die("该文件后缀不被允许"); } if ( $_FILES["m"]["error"] >$size){ die('文件大小超过限制'); } echo "文件{$_FILES['m']['name']}上传成功,文件大小{$_FILES["m"]["error"] }";