This section describes how to configure the php file upload function in the php. ini file. it involves some important options and restrictions on the size of php files to be uploaded. For more information, see. I will share some key PHP. ini configurations when using php to implement the file upload function. The php file upload function configuration mainly involves the upload_tmp_dir, upload_max_filesize, post_max_size, and other options in the php. ini configuration file. 1. descriptions of file upload configuration options in php. ini Open the php. ini configuration File and find File Uploads file_uploads = On. HTTP File upload is allowed by default. this option cannot be set to OFF. Upload_tmp_dir = The default value is null. if this option is not configured when you manually configure the PHP runtime environment, the file upload function cannot be implemented, this option sets the temporary directory for storing files during File upload. you must assign a value to this option. for example, upload_tmp_dir = '/leapsoulcn' indicates that there is a leapsoulcn directory under the C directory, like session configuration, if it is in a linux environment, you must grant the write permission to this directory. 2. how to upload a large file larger than 8 MB? Uploading large files involves configuring the upload_max_filesize and post_max_size options. Php. the default file upload size in the ini configuration file is 2 MB. The most common mistake is to set the form area of the maximum file size when writing the file upload function, that is, to allow the maximum file size to be uploaded, the value of max_file_size (hidden value range) is used to specify the size of the uploaded file. In fact, this value can be bypassed by others. for security reasons, it is best to use the value in php. configure the upload_max_filesize option in the ini configuration file to set the file upload size. The default upload_max_filesize = 2 M, that is, the file size is 2 M. If you want to upload files larger than 8 M, such as 20 M, you must set upload_max_filesize = 20 M. However, if you only set upload_max_filesize = 20 M, you still cannot upload large files. you must modify php. the post_max_size option in the ini configuration file, which indicates the maximum length of bytes allowed for POST data. the default value is 8 MB. If the POST data exceeds the limit, $ _ POST and $ _ FILES will be empty. To upload a large file, you must set the option value to be greater than the value of the upload_max_filesize command. Generally, the upload_max_filesize and post_max_size values are equal. In addition, if the memory limit is enabled, the value should be smaller than the value of the memory_limit option. III. Other considerations for file Upload When uploading a large file, you may feel that the upload speed is slow. if it exceeds a certain period of time, an error occurs that the script execution exceeds 30 seconds. in the ini configuration file, the max_execution_time configuration option is incorrect. it indicates the maximum allowed execution time (in seconds) of each script, and 0 indicates no limit. You can adjust the value of max_execution_time appropriately. it is not recommended to set it to 0. Now, the configuration of the file upload option in the php. ini configuration file is complete, and we hope to help you master the php file Upload method. |