Yesterday I shared my PHP tutorial on how to configure the session function in php. ini during PHP website development. Today I will continue to share some key PHP. ini configurations when using php to implement the file upload function.
When talking about the file upload configuration in php. ini, I mentioned the php file upload function code example tutorials and Jquery AjaxUpload code examples. 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.
Configuration Options of file upload 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. This option is easy to forget when you manually configure the PHP runtime environment. If this option is not configured, 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', which indicates that there is a leapsoulcn directory under the C directory, like session configuration, if you are in a linux environment, you must grant this directory write permission.
How do I upload large files larger than 8 Mb?
Uploading large files mainly involves configurationUpload_max_filesizeAndPost_max_sizeTwo options.
Php. the default file upload size in the ini configuration file is 2 MB. A common mistake for php beginners is to set the form area with the maximum file size when writing the file upload function, that is, the maximum value allowed to upload files. The value of max_file_size (hidden value range) specifies the size of the uploaded files. In fact, this value can be bypassed by others. For security reasons, it is best to use 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 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. I usually set the value of upload_max_filesize to be equal to that of post_max_size. In addition, if the memory limit is enabled, this value should be smaller than the value of the memory_limit option.
Other precautions 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.
So far, in php. the PHP tutorial for configuring File Upload options in the ini configuration file is complete. The file upload function can be implemented through the above steps, practices and learning, and the PHP program.
From: http://www.leapsoul.cn /? P = 488