处理代码:
1. <?php 2. header('Content-Type:text/html;charset=UTF-8'); 3. //准备接收 4. /* 5. echo '文件名:'.$_FILES['userfile']['name']; 6. echo '文件大小:'.$_FILES['userfile']['size']; 7. echo '错误:'.$_FILES['userfile']['error']; */ 8. 9. //print_r($_FILES) 10. $tmpFile=$_FILES['userfile']['tmp_name']; 11. if(is_uploaded_file($tmpFile)) 12. { 13. echo '正在上传。。。'; 14. 15. 16. if(!file_exists('uploads'))//如果文件夹不存在 17. { 18. mkdir('uploads'); 19. } 20. $moveFile =move_uploaded_file($tmpFile, 'uploads/'.$_FILES['userfile']['name']); 21. 22. if($moveFile) 23. { 24. echo "移动成功!"; 25. 26. //echo '<img src='.'uploads/'.$_FILES["userfile"]["name"].'> </img>'; 27. 28. }else 29. { 30. echo '移动失败!'; 31. } 32. 33. }else 34. { 35. echo "临时文件夹找不到文件"; 36. 37. } 38. ?>
HMTL代码:
1. <!DOCTYPE html> 2. <html> 3. <head> 4. <meta charset="UTF-8"> 5. <title>Insert title here</title> 6. </head> 7. <body> 8. <form enctype="multipart/form-data" action="fileUpload.php" method="post"> 9. <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> 10. 上传文件: <input type="file" name="userfile" /> 11. <input type="submit" value="上传" /> 12. </form> 13. </body> 14. </html>