Php Development file Upload

Source: Internet
Author: User
Php Development file Upload 1. configure the php. ini file
Set the following attribute values:


2. pre-defined variables
The list is as follows:

Create an upload domain and output the uploaded file information through the _ FILES variable. The sample code is as follows:

 
 "; } } ?>

The running result is as follows:

3. file upload function
Use the move_uploaded_file () function in php to upload files. The syntax is as follows:
Bool move_uploaded_file (string filename, string destination)
This function uploads a file to a specified position. if the file is successfully uploaded, true is returned. if the file fails, false is returned. The parameter filename is the temporary FILE name, that is, $ _ FILE [tmp_name]. the destination parameter is the new path and name saved after Upload.

The sample code is as follows:

 
 

The running result is as follows:

4. multifile Upload
There are multiple methods for uploading multiple files. next we will evolve a multifile Upload method based on a single file upload. The sample code is as follows:

  
 "; If (move_uploaded_file ($ file1 ['tmp _ name'], $ file1 ['name']) {echo" uploaded successfully
";} Else {echo" Upload failed
";}} If ($ file2 ['error'] = UPLOAD_ERR_ OK) {echo" path: ". $ file2 ['name']."
"; If (move_uploaded_file ($ file2 ['tmp _ name'], $ file2 ['name']) {echo" uploaded successfully
";} Else {echo" Upload failed
";}} If ($ file3 ['error'] = UPLOAD_ERR_ OK) {echo" path: ". $ file3 ['name']."
"; If (move_uploaded_file ($ file3 ['tmp _ name'], $ file3 ['name']) {echo" uploaded successfully
";} Else {echo" Upload failed
";}}?>

The running result is as follows:

The sample code for the second multi-file Upload method is as follows:

 
 $ Error) {if ($ error = UPLOAD_ERR_ OK) {echo "File name:". $ filearray ['name'] [$ key]."
"; If (move_uploaded_file ($ filearray ['tmp _ name'] [$ key], $ filearray ['name'] [$ key]) {echo" uploaded successfully
";} Else {echo" Upload failed
";}}?>

The running result is as follows:

In addition to the above two methods, there is also a third method for uploading multiple files. of course, I think the most perfect method is to select multiple files at a time for uploading. It is mainly implemented using swfupload. Due to my limited current knowledge, I will learn this with you later.

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.