php 文件上传实例代码

  1. <?php
  2. if(!$UploadAction):
  3. ?>
  4. <HTML>
  5. <HEAD>
  6. <TITLE>文件上载界面</TITLE>
  7. </HEAD>
  8. <BODY>
  9. <table>
  10. <tr align="center">//开源代码phpfensi.com
  11. <td><form ENCTYPE="multipart/form-data" NAME="SubmitForm" ACTION="upload.php教程" METHOD="POST">
  12. <input type="hidden" name="MAX_FILE_SIZE" value="1000000"><input type="hidden" name="UploadAction" value="1">
  13. </td></tr>
  14. <tr align="center">
  15. <td><input NAME="UploadFile" TYPE="file" SIZE="30"></td>
  16. </tr>
  17. <tr align="center">
  18. <td><input NAME="submit" VALUE="提交www.111cn.net" TYPE="submit"></td>
  19. <td><input NAME="reset" VALUE="重置" TYPE="reset"></td>
  20. </tr>
  21. </form>
  22. </table>
  23. </center>
  24. </BODY>
  25. </HTML>
  26. <?php
  27. else:
  28. ?>
  29. <HTML>
  30. <HEAD>
  31. <TITLE>文件上载代码</TITLE>
  32. </HEAD>
  33. <BODY>
  34. //代码如下:
  35. <?php
  36. $UploadAction=0;
  37. echo "Good!";
  38. $TimeLimit=60; /*设置超时限制时间 缺省时间为30秒 设置为0时为不限时 */
  39. set_time_limit($TimeLimit);
  40. If(($UploadFile !="none" ))
  41. {
  42. $UploadPath=AddSlashes(dirname($PATH_TRANSLATED))."\www.111cn.net\"; //上载文件存放路径
  43. $FileName=$UploadPath.$UploadFile_name; //上载文件名
  44. if($UploadFile_size < 1024) //上载文件大小
  45. {
  46. $FileSize=(string)$UploadFile_size." 字节";
  47. }
  48. elseif ($UploadFile_size <(1024 * 1024))
  49. {
  50. $FileSize=number_format((double)($UploadFile_size/1024), 1) . " KB";
  51. }
  52. else{
  53. $FileSize=number_format((double)($UploadFile_size / (1024 * 1024)), 1) . " MB";
  54. }
  55. if(!file_exists($FileName))
  56. {
  57. if(copy($UploadFile,$FileName))
  58. { echo "文件 $UploadFile_name ($FileSize)上载成功!"; }
  59. else
  60. { echo "文件 $UploadFile_name上载失败!"; }
  61. unlink($UploadFile);
  62. }
  63. else
  64. { echo "文件 $UploadFile_name已经存在!"; }
  65. }
  66. else
  67. { echo "你没有选择任何文件上载!"; }
  68. set_time_limit(30); //恢复缺省超时设置
  69. ?>
  70. <BR><A HREF = "upload.php">返回</A>
  71. </BODY>
  72. </HTML>
  73. <?php
  74. endif;
  75. ?>