Two php methods for uploading images _ php tips-php Tutorial

Source: Internet
Author: User
This article mainly introduces two methods for uploading images in php, using form upload, and uploadify for refreshing and uploading with progress bars, if you are interested, you can refer to image uploading, which is often used in projects. almost no project can be uploaded without images or files. This article introduces two common Upload methods. (Note: Here we only implement functions, rather than doing too many front-end styles)
1. use form Upload
This method is the most primitive Upload method. the front-end is a simple form, and the backend has PHP to process transmitted files.
First, check the front-end code upload.html.

 

The code for creating the php file handle. php is as follows:

$ File = $ _ FILES ['file']; // Obtain the transmitted data // Obtain the file name $ name = $ file ['name']; $ type = strtolower (substr ($ name, strrpos ($ name ,'. ') + 1); // Obtain the file type and convert it to lower case $ allow_type = array ('jpg', 'jpeg ', 'GIF', 'PNG '); // define the allowed Upload type // Determine whether the object type is allowed to be uploaded if (! In_array ($ type, $ allow_type) {// if not, stop the program running return directly;} // determine whether it is an if (! Is_uploaded_file ($ file ['tmp _ name']) {// if the return is not uploaded through http post;} $ upload_path = "D:/now /"; // upload file storage path // start to move the file to the corresponding folder if (move_uploaded_file ($ file ['tmp _ name'], $ upload_path. $ file ['name']) {echo "Successfully! ";} Else {echo" Failed! ";}

Of course, the php processing code is not perfect, but the error is not handled. However, the principle of using php to process uploaded files is as follows. you can optimize it on this basis, make it more complete.
II. use uploadify for refreshing and uploading with progress bars
First download the uploadify plug-in, save it under a folder in the project, and then introduce three files

 

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.