Home > Backend Development > PHP Tutorial > A php source code for uploading and downloading files

A php source code for uploading and downloading files

WBOY
Release: 2016-07-25 09:07:32
Original
1390 people have browsed it
  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. ?>
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template