PHP upload file can not be uploaded successfully,$_files[& #39;screenshot& #39;] [& #39;tmp_name& #39;] Tutorial for empty _php

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

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


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:

  
 
  
   <title>Guitar Wars-add Your High Score</title>  
 
  
   

Guitar Wars-add Your High Score

";//echo" Score: $score
";//echo" screenshot: $screenshot
"; if (!empty ($name) &&!empty ($score) &&!empty ($screenshot)) {//Move the file to the target upload F Older $target = Gw_uploadpath. $screenshot; echo Json_encode ($_files); if (Move_uploaded_file ($_files[' screenshot ' [' Tmp_name '], $target)) {//Connect to the DATABASE$DBC = Mysqli_connec T (Db_host, Db_user, Db_password, db_name) or Die (' Error connecting to MySQL database! '); /Write The data to the Database$query = "INSERT into Guitarwars VALUES (0, now (), ' $name ', ' $score ', ' $screenshot ')"; MySQL I_query ($DBC, $query) or Die (' Error querying database; '); /Confirm success with the Userecho '

Thanks for adding your new high score!

'; Echo '

Name: ' . $name. '
'; Echo 'score: '. $score, Echo '

'; Echo '

<< back to high scores

';//clear the score data to clear the Form$name = ""; $score = ""; $screenshot = ""; Mysqli_close ($DBC); }} else {echo '

Please enter any of the information to add your high score.

'; }}?>

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 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 succeeded. 1; The size of the system is exceeded in the file size php.ini. 2; The value specified by the File size max_file_size option is exceeded. 3; Only part of the file is uploaded. 4; No files were uploaded. 5; The 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

 
  $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 resulting in 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.


http://www.bkjia.com/PHPjc/847869.html www.bkjia.com true http://www.bkjia.com/PHPjc/847869.html techarticle php upload files can not be uploaded successfully, $_files[#39; screenshot#39;] [#39; tmp_name#39;] Empty recently in the 5th chapter of the book "Headfirst PHP MySQL", "Using data stored in a file" ...

  • Related Article

    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.