Simple example of php file Upload

Source: Internet
Author: User
Tags php file upload
Simple example of php file Upload

  1. /**
  2. * Upload files in php
  3. * Edit: bbs.it-home.org
  4. */
  5. If ($ _ FILES ["file"] ["type"] = "image/gif ")
  6. | ($ _ FILES ["file"] ["type"] = "image/jpeg ")
  7. | ($ _ FILES ["file"] ["type"] = "image/pjpeg "))
  8. & ($ _ FILES ["file"] ["size"] <20000 ))
  9. {
  10. If ($ _ FILES ["file"] ["error"]> 0)
  11. {
  12. Echo "Return Code:". $ _ FILES ["file"] ["error"]."
    ";
  13. }
  14. Else
  15. {
  16. Echo "Upload:". $ _ FILES ["file"] ["name"]."
    ";
  17. Echo "Type:". $ _ FILES ["file"] ["type"]."
    ";
  18. Echo "Size:". ($ _ FILES ["file"] ["size"]/1024). "Kb
    ";
  19. Echo "Temp file:". $ _ FILES ["file"] ["tmp_name"]."
    ";
  20. If (file_exists ("upload/". $ _ FILES ["file"] ["name"])
  21. {
  22. Echo $ _ FILES ["file"] ["name"]. "already exists .";
  23. }
  24. Else
  25. {
  26. Move_uploaded_file ($ _ FILES ["file"] ["tmp_name"], "upload/". $ _ FILES ["file"] ["name"]); // comment
  27. Echo "Stored in:". "upload/". $ _ FILES ["file"] ["name"];
  28. }
  29. }
  30. }
  31. Else
  32. {
  33. Echo "Invalid file ";
  34. }
  35. ?>

Code description: When a php file is uploaded, a temporary folder exists. if the file is not moved, the temporary file will be automatically deleted after the script is complete. The above line of code is to save the uploaded file. The saved directory is the upload folder under the current directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.