Home>Article>Daily Programming> Detailed explanation of PHP file upload method and information analysis [with video]
This article mainly introduces the PHP file upload method and its information analysis in detail.
Using PHP to implement the file upload function is relatively common in PHP project development, but it may be difficult for some novices. Below we will explain it in detail through specific code examples.
First create an HTML form for file upload.
The code example is as follows:
Title
The effect is as shown:
#In the above code, we set the file type for the input button, and set the uploaded file name to file. When we click to select a file or image, the form data will be sent to upload.php, and then related operations will be performed on the uploaded file.
Then in the upload.php file, we will define a method to analyze the relevant information of the uploaded file.
The specific code example is as follows:
In the above PHP code, a variable $fileInfo is defined to receive the data uploaded from the form, and then use the var_dump function to print out the information of the uploaded file file and display it in an array.
Then when there is no way to judge the file, the effect of accessing it directly through the browser is as follows:
## Tip: error represents the error message. The error number here is 0, which means that the uploaded file does not have any errors. But in the PHP manual, the error number is more than 0.
The following is a brief summary of the error number situations in table form
The value is 2 | The value is 3 | The value is 4 | The value is 6 | When the value is 7 | ||
The uploaded file exceeds the value of the upload_max_filesize option in php.ini. | The size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form. | Only part of the file was uploaded. | No files were uploaded | The temporary folder cannot be found. Introduced in PHP 4.3.10 and PHP 5.0.3. | File writing failed. Introduced in PHP 5.1.0. |
Then use if else and switch judgment statements to judge the uploaded files one by one.
The method here is based on the type of file, the existence of the upload folder, and the error message. Finally, after we upload a picture, the final effect displayed is as follows: ##Note:md5() in the above code The function is not used for encryption, but for encoding.The above article is about the specific method of uploading PHP files. I hope it will be helpful to friends in need! The corresponding
Video Tutorialis [PHP File Upload Information Analysis and Encapsulation Upload Method] for your reference and study!
The above is the detailed content of Detailed explanation of PHP file upload method and information analysis [with video]. For more information, please follow other related articles on the PHP Chinese website!