PHP Single file and multi-file upload instance explanation

Source: Internet
Author: User
This article gives you a detailed analysis of the PHP implementation of single-file upload and multi-file upload code and problem-solving solutions, together with the study reference.

$_files when is an empty array?

form submission Enctype not equal to Multipart/form-data when php.ini config file, file_uploads = Off uploaded file size > php.ini config file with maximum uploaded hours configured

As long as the occurrence of $_files is an empty array, the above problems may occur, must be fixed!

If you do not select any files, click the "Upload button" immediately, $_files will be an array with elements, each attribute in the element is an empty string, the error property is 4

Single File Upload

$_files Data structure

Array ('  filename ' = = Array (    ' name ' = ' = ' xxx.png ',    ' type ' = ' image/png ',    ' size ' = = 2548863,    ' tmp_name ' = '/img/sdsdsd.png ',    ' error ' = 0  )

There are 单文件 多文件上传 5 fixed properties, either, or both: Name/size/type/tmp_name/error

Multiple file uploads

Compared to single file upload, multi-file upload processing is more complicated than the front-end two kinds of multi-file upload form

Name same <form method= "post" enctype= "Multipart/form-data" >  <input type= "file" Name= "wt[]"/>  <input type= "File" Name= "wt[]"/>  <input type= "Submit" value= "Submit"/></form>//name different (simple point) < Form method= "POST" enctype= "Multipart/form-data" >  <input type= "file" name= "wt"/> <input  type= " File "name=" MMT "/>  <input type=" Submit "value="/></form> "


The corresponding data structure of the backend is $_FILES different

Name of the same array (size=1) ' wt ' = = Array (size=5) ' name ' = = Array (size=2) 0 = + string ' New text document (2). txt ' ( length=26) 1 = string ' new text document. txt ' (length=22) ' type ' = = Array (size=2) 0 = String ' Text/plain ' ( length=10) 1 = String ' Text/plain ' (length=10) ' tmp_name ' = = Array (size=2) 0 = = String ' C:\Window     S\php1d64.tmp ' (length=22) 1 = String ' C:\Windows\php1D65.tmp ' (length=22) ' ERROR ' = = Array (size=2)  0 = int 0 1 = int 0 ' size ' = = Array (size=2) 0 = int 0 1 = int 1820//name different (simple point) array (size=2) ' wt ' = = Array (size=5) ' name ' = ' + string ' new text document (2). txt ' (length=26) ' type ' = = String ' Text/plain ' (length=   ' Tmp_name ' = = String ' C:\Windows\php39C7.tmp ' (length=22) ' ERROR ' = int 0 ' size ' + int 0 ' MMT ' = Array (size=5) ' name ' = + string ' new text document. txt ' (length=22) ' type ' = = String ' Text/plain ' (length=10) ' Tmp_name ' = = string ' C:\Windows\php39D8.tmp ' (length=22) ' ERROR ' = int 0 ' size ' + int 1820 

Field Error usage

Value: 1 The uploaded file exceeds the value of the Upload_max_filesize option limit in php.ini.

Value: 2 The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form.

Value: 3 files are only partially uploaded.

Value: 4 No files were uploaded. Value: 5 The Upload file size is 0.

The principle analysis of PHP Multi-person module development

Use Xhprof to find examples of PHP performance bottlenecks

Summary of custom template directives in the Laravel framework

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.