Php image upload code example

Source: Internet
Author: User
Php image upload code example
Php implements the image upload code, which can determine the file size, type, and generate the file name by year, month, day, minute, and second. this is suitable for beginners.

The code is as follows.

 
     $ File_size_max) {echo "Sorry, your file capacity exceeds the limit"; exit;} // Check the read/write file if (file_exists ($ store_dir. $ upload_file_name) & $ accept_overwrite) {Echo "file with the same file name"; exit;} // copy the file to the specified directory if (! Move_uploaded_file ($ upload_file, $ store_dir. $ newname) {echo "file copy failed"; exit ;}} Echo"

You uploaded the file: "; echo $ _ FILES ['upload _ file'] ['name']; echo"
"; // The original name of the client machine file. Echo "the MIME type of the file is:"; echo $ _ FILES ['upload _ file'] ['type']; // The MIME type of the file, the browser must provide support for this information, such as "image/gif ". Echo"
"; Echo" size of the uploaded file: "; echo $ _ FILES ['upload _ file'] ['size']; // size of the uploaded file, in bytes. Echo"
"; Echo" the file is temporarily stored after being uploaded: "; echo $ _ FILES ['upload _ file'] ['tmp _ name']; // temporary file name stored on the server after the file is uploaded. Echo"
"; $ Erroe = $ _ FILES ['upload _ file'] ['error']; switch ($ Erroe) {case 0: Echo" uploaded successfully "; break; case 1: Echo "the uploaded file exceeds php. the value of the upload_max_filesize option in ini. "; break; case 2: Echo" the size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form. "; Break; case 3: Echo" only part of the file is uploaded "; break; case 4: Echo" no file is uploaded "; break ;}// image Upload processing?>

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.