先来写一下HTML上传文件的代码:
<form enctype="multipart/form-data" action="upload.php" method="POST"> <!--文件的最大限制 --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> Send this file: <input name="upfile" type="file" /> <input type="submit" value="Send File" /> </form>
多次运行发现代码错误:
<?php $uploaddir = "/uploaded/"; $uploadfile = $uploaddir.basename($_FILES['upfile']['name']); echo $uploadfile; if(move_uploaded_file($_FILES['upfile']['tmp_name'],$uploadfile)){ echo "File is valid, and was successfully uploaded. "; }else{ echo "error"; } ?>
没有这个文件或路径?
好吧 修改代码:
<?php //这里没有了前面的 "/" $uploaddir = "uploaded/"; $uploadfile = $uploaddir.basename($_FILES['upfile']['name']); echo $uploadfile; if(move_uploaded_file($_FILES['upfile']['tmp_name'],$uploadfile)){ echo "File is valid, and was successfully uploaded. "; }else{ echo "error"; } ?>
好了 实现上传了.