PHP Image Upload code example

Source: Internet
Author: User

PHP File Upload code example

  1. Image upload
  2. $max _file_szie=2*pow (2,20); The uploaded file is less than 2MB
  3. $destination _folder= ' uploadimg/'; Upload File Save path
  4. if ($_server[' Request_method ']== ' POST ') {
  5. if (!is_uploaded_file ($_files[' upfile ' [' tmp_name '])) {
  6. echo ' picture does not exist! ';
  7. Exit
  8. }
  9. if ($max _file_szie<$_files[' upfile ' [' size ']) {
  10. Echo ' file is too big! ';
  11. Exit
  12. }
  13. if (!in_array ($_files[' upfile ' [' type '], $uptypes)) {
  14. echo ' file type does not match! '. $_files[' upfile ' [' type '];
  15. Exit
  16. }
  17. if (!file_exists ($destination _folder)) {
  18. mkdir ($destination _folder);
  19. }
  20. $filename =$_files[' upfile ' [' tmp_name '];
  21. $image _size=getimagesize ($filename);
  22. $pinfo =pathinfo ($_files[' upfile ' [' name ']); File path information
  23. $ftype = $pinfo [' extension ']; Old file suffix name
  24. $destination = $destination _folder.time (). ".". $ftype; New file name
  25. if (file_exists ($destination) && $voerwrie!=true) {
  26. Echo ' file with the same name already exists! ';
  27. Exit
  28. }
  29. Move the uploaded file from the Temp folder to the specified directory
  30. if (!move_uploaded_file ($filename, $destination)) {
  31. Echo ' moved the file wrong! ';
  32. Exit
  33. }
  34. $pinfo =pathinfo ($destination);
  35. $fname = $pinfo [basename];
  36. echo "has been successfully uploaded
    Filename:
  37. ". $destination _folder. $fname."
    ";
  38. echo ' width: '. $image _size[0];
  39. echo ' Height: '. $image _size[1];
  40. Echo '
    Size: '. $_files[' upfile ' [' Size ']. " Bytes ";
  41. }
  42. ?>
Copy Code
Image upload, PHP
  • 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.