1. Modify and set the size of the uploaded file.
2. Add "php_value upload_max_filesize "300M"" to it.
3. Just restart the server.
Using ThinkPhp framework to upload small image files successfully, but failed to upload large files.
Later, I found the reason because PHP restricts the size of uploaded files, and modified the following configuration:
upload_max_filesize = 300M post_max_size = 300M
Restarting the server, it's still the same, the problem has not been resolved.
The solution is as follows, add it as follows:
php_value upload_max_filesize "300M" php_value post_max_size "300M"
Restart the server again, OK!
Knowledge point expansion:
Error handling
The error attribute in the file array is judged:
$error=$myfile['myfile']['error']; if ($error==0){//It is 0, which means the upload is successful if (move_uploaded_file($tmp,"userpic/".$picname)) { echo "Moving the file successfully"; }else{ echo "Failed to move files"; } }else{//Not 0, match error message switch ($error){ case 1: echo "Exceeding maximum file upload limit";// upload_max_filesize break; case 2: echo "Exceed form file size limit";//The MAX_FILE_SIZE option in the HTML form break; case 3: echo "The file part is uploaded"; break; case 4: echo "Upload file not selected"; break; case 7://File writing failed case 8: echo "System Error"; break; } }
Upload restrictions
On the front end, you can limit the uploaded file type and size:
<!--The form hidden domain limits upload size--> <input type="hidden" name="MAX_FILE_SIZE" value="2097152"> <!--accept Limitations on file types--> <input type="file" name="myfile" accept="image/jpeg,image/png">
Note that the limit is in bytes
Response restrictions must be made on the server side:
$size=$myfile['size'];//Get file size$MaxSize=2097152;//Set the maximum allowable byte$type=$myfile['type'];//Get picture type$AllowTypr=array('image/jpeg','image/png','image/gif');//Allow type arrayif ($error==0){//It is 0, which means the upload is successful if ($size>$MaxSize){ echo "<script>alert('File size exceeds limit');</script>"; echo "<script>(1);</script>"; exit(); } if (!in_array($type,$AllowTypr)){ echo "<script>alert('Please upload the correct image type');</script>"; echo "<script>(1);</script>"; exit(); }
This is the article about the example analysis and solution of php no file uploaded. For more related php no file uploaded, please search for my previous article or continue browsing the related articles below. I hope everyone will support me in the future!