Php file upload problems

Source: Internet
Author: User
Tags php file upload
Php file Upload question & lt ;? Phpheader ('content-Type: & nbsp; text/html; & nbsp; charset = gbk'); echo & nbsp; '& lt; pre & gt ;'; print_r ($ _ FILES); echo & php file upload problems
Header ('content-Type: text/html; charset = gbk ');
Echo'
';
print_r($_FILES);
echo '
';
Echo'
';
If ($ _ FILES ['userfile'] ['error']> 0 ){
Switch ($ _ FILES ['userfile'] ['error']) {
Case 1: echo "script" alert ('The file uploaded exceeds the agreed value of 1'); history. back (); script ";
Break;
Case 2: echo "script" alert ('The file uploaded exceeds the agreed value of 2'); history. back (); script ";
Break;
Case 3: echo "script" alert ('partially uploaded '); history. back (); script ";
Break;
Case 4: echo "script" alert ('No files uploaded '); history. back (); script ";
Break;
}
Exit;
}
If (is_uploaded_file ($ _ FILES ['userfile'] ['tmp _ name'])
{
If (! Move_uploaded_file ($ _ FILES ['userfile'] ['tmp _ name'], 'uploads'/'. $ _ FILES ['userfile'] ['name'])
{
Echo "script alert ('moving failed! '); History. back (); script ";
Exit;
}

} Else {
Echo "script" alert ('file uploaded cannot be found in the temporary folder '); history. back (); script ";
Exit;
}
Echo "script" alert ('file uploaded successfully! '); Location. href = 'demo3. php? Url = ". $ _ FILES ['userfile'] ['name']." '; script ";
?> Why can I upload a small file correctly and display all the information of $ _ FILES? however, when uploading a large file, the S_FILES information is not displayed and the output is "Array ()", in addition, you can bypass the if ($ _ FILES ['userfile'] ['error']> 0) statement and directly prompt 'upload file not found in the temporary folder, ask the experts to explain why this problem occurs? PHP: '; print_r ($ _ FILES); echo... 'data-pics = ''>
------ Solution --------------------
The value of the max_file_uploads post_max_size memory_limit parameter in your php. ini file cannot exceed this value.
------ Solution --------------------
As mentioned above, the size of the file you uploaded exceeds the maximum file size limit in INI. in this case, the file cannot be uploaded, that is, $ _ FILES ['name'] will be an empty array. of course, $ _ FILES ['name'] ['error'] will not be greater than 0, and you will jump directly to the back.

The best solution is to cut the upload and not upload all at once. you can use ajax to split the file.
------ Solution --------------------
If post_max_size is not set, it will use the default value of 8 M. your large file must exceed 8 M, so $ _ FILES will be blank.

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.