PHP.INI configuration: configuration file upload function

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags code configuration configure default directory example examples file

This article describes the file upload in php.ini configuration, in fact, prior to this site introduced PHP file upload function code examples tutorial and Jquery AjaxUpload file upload function code example tutorial I have mentioned. PHP file upload function configuration mainly involves php.ini configuration file upload_tmp_dir, upload_max_filesize, post_max_size and other options.
php.ini file upload feature configuration options

Open the php.ini configuration file to find File Uploads

file_uploads = On

HTTP file upload is allowed by default. This option can not be set to OFF.

upload_tmp_dir =

Default is empty, this option is also easy to forget when manually configuring the PHP operating environment, if you do not configure this option, the file upload function can not be achieved, this option is set to the file upload temporary file directory, you must give this option Assignment, such as upload_tmp_dir = '/ leapsoulcn' on behalf of the directory in the C drive has a leapsoulcn directory, and session configuration, if you are in linux environment, you must give this directory write permission.

How to upload large files over 8M?

Upload large files mainly involves configuring upload_max_filesize and post_max_size two options.

php.ini configuration file default file upload size of 2M, php for beginners is easy to make a mistake in writing the file upload function by setting the maximum size of the upload file form area, which allows the maximum file upload, max_file_size (hidden The value of the domain) value to regulate the size of the uploaded file, in fact, other people can bypass this value, so for safety's sake, it is best to configure upload_max_filesize option in the php.ini configuration file to set the file upload size.

The default upload_max_filesize = 2M, the file upload size is 2M, if you want to upload more than 8M files, such as 20M, you must set upload_max_filesize = 20M.

But the light set upload_max_filesize = 20M still can not achieve the function of uploading large files, you must modify the php.ini configuration file post_max_size option, which represents the maximum allowable byte length POST data, the default is 8M. If POST data exceeds the limit, $ _POST and $ _FILES will be empty. To upload large files, you must set the value of this option to be greater than the value of the upload_max_filesize directive. I generally set the values ​​of upload_max_filesize and post_max_size equal. In addition if the memory limit is enabled, then the value should be less than the value of the memory_limit option.

Other notes on file upload

Upload large files, you will have the feeling of slow upload, when more than a certain period of time, the script will be reported to perform more than 30 seconds error, this is because in the php.ini configuration file max_execution_time configuration options at play, which means that each The maximum allowable execution time of a script (seconds), 0 means there is no limit. You can properly adjust the value of max_execution_time, it is not recommended to set to 0.

At this point, php.ini configuration file on the file upload options to configure the PHP tutorial is introduced, through the above steps to practice and learn, combined with the PHP program, file upload function can be achieved.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.