当前位置:Gxlcms > PHP教程 > 一个php上传下载文件的源码

一个php上传下载文件的源码

时间:2021-07-01 10:21:17 帮助过:26人阅读

  1. filelist


  2. $dir = 'upload/';
  3. if(is_dir($dir)) {
  4. if ($dh = opendir($dir)) {
  5. while (($file = readdir($dh)) !== false) {
  6. if($file!="." && $file!="..") {
  7. echo "
  8. ";
  9. }
  10. }
  11. closedir($dh);
  12. }
  13. }
  14. ?>
  15. ".$file."

#----------------- 文件:upload_file.php

  1. if ($_FILES["file"]["error"] > 0)
  2. {
  3. echo "Return Code: " . $_FILES["file"]["error"] . "
    ";
  4. }
  5. else
  6. {
  7. echo "Upload: " . $_FILES["file"]["name"] . "
    ";
  8. echo "Type: " . $_FILES["file"]["type"] . "
    ";
  9. echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
    ";
  10. echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
    ";
  11. if (file_exists("upload/" . $_FILES["file"]["name"]))
  12. {
  13. echo $_FILES["file"]["name"] . " already exists. ";
  14. }
  15. else
  16. {
  17. move_uploaded_file($_FILES["file"]["tmp_name"],
  18. "upload/" . $_FILES["file"]["name"]);
  19. echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  20. }
  21. }
  22. header('HTTP/1.1 301 Moved Permanently');
  23. header('Location:files.php');
  24. ?>

人气教程排行