Home > Article > Backend Development > Things you need to pay attention to when uploading large images in PHP
This article introduces to you the points that need to be paid attention to when uploading large images in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Front-end precautions for uploading images in php
Form form upload example
<form name="form" action="upload.php" enctype="multipart/form-data"> First name:<br> <input type="text" name="firstname"> <br> Last name:<br> <input type="text" name="lastname"> <input type="file" name="image"> <input type="submit" value="提交"></form>
The form header must be set enctype="multipart/form-data ", indicates that the file is uploaded in binary form, so that multiple types of file uploads can be implemented.
2. Things that need to be set in php.ini
The maximum image uploaded by php by default is 2M. In actual situations, files larger than 2M may be encountered. Upload.
We need to modify the following options:
file_uploads = On; turn on the file upload option (mode on)
upload_max_filesize = 20M; upper limit of uploaded files (default is 2M)
post_max_size = 20M; upper limit of post (default is 8M)
Adjust the following options according to the actual situation:
max_execution_time = 180; The maximum execution time of the script (seconds). If it is too short, the script will stop before the file is uploaded (the default is 30 Second).
max_input_time = 180; The maximum transmission time requested. If it is too short, the transmission will stop before the file is uploaded (default is 60 seconds).
memory_limit = 128M; upper limit of memory
3. Server configuration
If you are using a high-performance nginx server, you need to do the following configuration:
Open In the nginx configuration file nginx.conf, add a client_max_body_size 20m configuration item in http{} and restart the nginx.service service.
Recommended related articles:
How to process images (code) when php and ajax are combined
_get method and _ in php Example code of set method access method
The above is the detailed content of Things you need to pay attention to when uploading large images in PHP. For more information, please follow other related articles on the PHP Chinese website!