PHP upload file can not be uploaded successfully, $_files[' screenshot ' [' Tmp_name '] is empty

Source: Internet
Author: User
Tags html form php programming php programming language zend

Recently, in the 5th chapter of the book "Headfirst PHP & MySQL", "Using data stored in Files", a file upload application, an error occurred, that is, the file cannot be uploaded successfully. This problem has plagued me for a long time, but fortunately finally solved. The reason is that I uploaded a picture file larger than the value specified by the MAX_FILE_SIZE option in the HTML form 32768Bytes that 32KB caused the upload to succeed.

I used the XAMPP (Apache + MySQL + PHP + Perl) integration package and Zend Studio 10.6 as the PHP IDE development environment, in addition to PHP debugging I used the Xdebug, in Zend Studio10.6 Configuration I refer to the blog post Zend Studio 10.5 with XDebug debugging | Zend Debugger Description Drupal Source code (i)

The PHP code for my addscore.php is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
when I debug the above PHP code using Zend Sutdio10.6 I find "if (Move_uploaded_file ($_files[' screenshot ' [' Tmp_name '], $target)) {" The code block inside this line of code is not executed, and the value of the Super global variable $_files[' screenshot ' [' Tmp_name '] is empty, and then I print out the value of the $_files variable in JSON format before this line of code, as follows:

{"screenshot": {"name": "Penguins.jpg", "type": "", "Tmp_name": "", "Error": 2, "size": 0}}

As follows:


Then I query $_files[' screenshot ' [' Error '] for 2, surf the internet for a bit, about the $_files Super global variables are generally as follows:

Common $_files system function usages in the PHP programming language are:$_files[' myFile ' [' name '] Displays the original name of the client file. $_files[The MIME type of the ' myFile ' [' type '] file, such as "Image/gif". $_files[' myFile ' [' size '] the size of the uploaded file, in bytes. $_files[' myFile ' [' tmp_name '] The temporary file name stored, usually the system default. $_files[' myFile ' [' ERROR '] The file uploads the relevant error code. The following are the meanings represented by different codes:0. File upload is successful. 1; exceeds the size of the file size php.ini the system setting. 2. File size exceededthe value specified by the max_file_size option. 3; The file is only partially uploaded. 4; No files are uploaded. 5; Upload file size is 0.

In addition, the query PHP reference manual about the Move_uploaded_file function is described below:


Example

Example #1 Uploading multiple files

<?php$uploads_dir = '/uploads '; foreach ($_files["Pictures"] ["error"] as $key = $error) {    if ($error = = Upload_ ERR_OK) {        $tmp _name = $_files["Pictures" ["Tmp_name"] [$key];        $name = $_files["Pictures" ["Name"] [$key];        Move_uploaded_file ($tmp _name, "$uploads _dir/$name");    
The reason is finally found, because I uploaded a 32768Bytes, or 32KB size of the penguins.jpg file caused the occurrence of $_files[' screenshot ' [' Error '] is 2 error, and $_files[' screenshot ' [' Tmp_name '] is empty, move_uploaded_file ($_files[' Screenshot '] [' tmp_name '], $target) function call returns FALSE,IF (Move_uploaded_file ($_files[' screenshot ' [' Tmp_name '], $target) ) {
...
The code block was not executed.


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.