Introduction to the file upload _ PHP instance through a simple php instance

Source: Internet
Author: User
This article describes how to upload a PHP file through code examples, obtain information about the file name, type, size, and so on, and upload the file. This article is of great reference value. I would like to share with you the script home platform, this is a simple example of PHP File Upload. You can obtain the file name, type, size, and other information to complete file upload for your reference.

1. Code for uploading files:

Code

<? Php // determine whether the temporary file storage path contains the user-uploaded file if (is_uploaded_file ($ _ FILES ["uploadfile"] ["tmp_name"]) {// for higher efficiency, store the information in the variable $ upfile =$ _ FILES ["uploadfile"]; // use an array string to store the information of the uploaded file. // print_r ($ upfile ); // If printed, the output is similar to this information Array ([name] => m.jpg [type] => image/jpeg [tmp_name] => C: \ WINDOWS \ Temp \ php1A. tmp [error] => 0 [size] => 44905) $ name = $ upfile ["name"]; // The name $ type = $ upfile ["type"] When transferring a file later; // The type of the uploaded file $ size = $ upfile ["size"]; // size of the uploaded file $ tmp_name = $ upfile ["tmp_name"]; // temporary name of the file uploaded by the user $ error = $ upfile ["error"]; // error message during the upload process // echo $ name; // determine the file type to determine whether to transfer the file, if yes, set $ OK = 1 to switch ($ type) {case "image/jpg": $ OK = 1; break; case "image/jpeg ": $ OK = 1; break; case "image/gif": $ OK = 1; break; default: $ OK = 0; break ;} // if the file meets the requirements and there is no error during the upload if ($ OK & $ error = '0') {// call the move_uploaded_file () function, file Transfer move_uploaded_file ($ tmp_name, 'Up /'. $ name); // after the operation is successful, the system prompts echo"

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.