PHP files cannot be uploaded successfully because they have exceeded the maximum file size. & nbsp; I recently studied HeadFirstPHP & amp; in MySQL, Chapter 1 "using data stored in files" appears when an error occurs during a file upload application, that is, the file cannot be uploaded successfully. This problem has plagued me for a long time, but fortunately it was finally solved. The reason is that the size of the uploaded image file exceeds the size limit of the file uploaded by MAX_FIL PHP in the HTML form, and the file cannot be uploaded successfully.
I recently learned "using data stored in files" in chapter 1 of "HeadFirst PHP & MySQL" and encountered an error during file upload, that is, the file cannot be uploaded successfully. This problem has plagued me for a long time, but fortunately it was finally solved. The reason is that the size of the uploaded image file exceeds the value of 32768Bytes specified by the MAX_FILE_SIZE option in the HTML form, that is, 32KB.
I used XAMPP (Apache + MySQL + PHP + Perl) integrated development kit and Zend Studio 10.6 as the php ide development environment. In addition, I used XDebug for PHP debugging, in Zend Studio10.6, configure the Xdebug PHP debugging environment. I have referenced Zend Studio 10.5 and XDebug debugging. | Zend Debugger describes Drupal source code (I.
The corresponding file upload example PHP code addscore. php is as follows:
Guitar Wars - Add Your High Score
Guitar Wars - Add Your High Score
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 all of the information to add your high score.
'; } }?>
When I set a breakpoint using Zend sudio10.6 and debug the above PHP code, I found that "if (move_uploaded_file ($ _ FILES ['screenshot '] ['tmp _ name'], $ target )) {"the code block in this line of code is not executed, so the value of the Super global variable $ _ FILES ['screenshot '] ['tmp _ name'] is empty, then, I printed the $ _ FILES variable value in JSON format before this line of code, as shown below:
{"screenshot":{"name":"Penguins.jpg","type":"","tmp_name":"","error":2,"size":0}}
The corresponding operation is as follows:
Then, I queried $ _ FILES ['screenshot '] ['error'] to 2. I checked it online. the introduction to the $ _ FILES Super global variable is as follows:
Common $ _ FILES system functions in PHP programming are used as follows:
$ _ FILES ['myfile'] ['name'] displays the original name of the client file.
$ _ FILES ['myfile'] ['type'] MIME type of the file, for example, "image/gif ".
$ _ FILES ['myfile'] ['size'] size of the uploaded file, in bytes.
$ _ FILES ['myfile'] ['tmp _ name'] indicates the temporary file name, which is generally the default file name.
$ _ FILES ['myfile'] ['error'] error code related to file upload. The meanings of different codes are as follows:
0: The file is uploaded successfully.
1: The file size exceeds the size set by the system in php. ini.
2: exceeds the file size
The value specified by the MAX_FILE_SIZE option.
3;: only part of the file is uploaded.
4: no files are uploaded.
5: The size of the uploaded file is 0.
In addition, the move_uploaded_file function in the PHP Reference Manual is described as follows:
Move_uploaded_file (PHP 4> = 4.0.3, PHP 5) move_uploaded_file-move the uploaded file to a new location description bool move_uploaded_file (string $ filename, string $ destination) this function checks and ensures that the file specified by filename is a valid file to be uploaded (that is, the file is uploaded through the http post Upload mechanism of PHP ). If the file is valid, move it to the file specified by destination. This check is especially important. if the uploaded file may display the content to the user or other users in the system. The file name uploaded by the filename parameter. Destination moves the file to this location. Returns TRUE if the return value is successful. If filename is not a valid file to be uploaded, no operation is performed. move_uploaded_file () returns FALSE. If filename is valid but cannot be moved for some reason, no operation will occur. move_uploaded_file () returns FALSE. A warning is also issued.
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 that I uploaded a penguins.jpg file that is later than 32768bytesand 32kb2. as a result, the error "$ _ FILES ['screenshot '] ['error'] is 2, and $ _ FILES ['screenshot '] ['tmp _ name'] is empty. move_uploaded_file ($ _ FILES ['screenshot'] ['tmp _ name'], $ target) if (move_uploaded_file ($ _ FILES ['screenshot '] ['tmp _ name'], $ target )){
...
} The code block is not executed.