欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-04-24 16:55:40
...
  1. filelist
  2. enctype="multipart/form-data">


  3. $dir = 'upload/';
  4. if(is_dir($dir)) {
  5. if ($dh = opendir($dir)) {
  6. while (($file = readdir($dh)) !== false) {
  7. if($file!="." && $file!="..") {
  8. echo "
  9. ";
  10. }
  11. }
  12. closedir($dh);
  13. }
  14. }
  15. ?>
  16. ".$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. ?>
复制代码