PHP File Upload related configuration tutorial

Source: Internet
Author: User
Tags execution file upload ini php file php file upload php tutorial

This article mainly describes the PHP file upload with the relevant configuration of knowledge points. PHP File Upload function Configuration mainly involves the php.ini configuration file in the Upload_tmp_dir, Upload_max_filesize, post_max_size and other options, the following one by one instructions.

Open php.ini configuration file to find file uploads

File_uploads = On

HTTP file uploads are allowed by default, and this option cannot be set to OFF.

Upload_tmp_dir =

The default is NULL, this option in the manual configuration of the PHP operating environment, also easy to forget, if not configured this option, file upload function can not be implemented, this option is set file upload files in the temporary directory, you must give this option to assign values, such as Upload_tmp_dir = '/ LEAPSOULCN ', the representative in the C disk directory has a LEAPSOULCN directory, and session configuration like, if you are in the Linux environment, you must give this directory writable permissions.

How do I upload a large file over 8M?

Uploading large files mainly involves configuring Upload_max_filesize and post_max_size two options.

Default file upload size in php.ini profile for 2m,php Beginners An error is to make the file upload function by setting the maximum size of the upload file form area, that is, the maximum allowable upload file, Max_file_ Size (hidden range) value to specify the size of the upload file, in fact, other people can bypass this value, so security, it is best to configure the Upload_max_filesize option in the php.ini configuration file, set the file upload size.

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

But the light setting upload_max_filesize = 20M still cannot achieve the upload function of the large file, you must modify the Post_max_size option in the php.ini configuration file, which represents the maximum byte length of the data allowed to post, and the default is 8M. If the post data exceeds the limit, then $_post and $_files will be empty. To upload a large file, you must set the value of this option is greater than the value of the upload_max_filesize instruction, I generally set upload_max_filesize and post_max_size values equal. In addition, if the memory limit is enabled, the value should be less than the value of the Memory_limit option.

Additional Considerations for file uploads

When uploading large files, you will have a slow upload feeling, when more than a certain amount of time, will report the script execution more than 30 seconds of error, because in the php.ini configuration file max_execution_time configuration options in the mischief, which represents the maximum allowable execution time per script (seconds), 0 Indicates no limit. You can adjust the Max_execution_time value appropriately, not recommend setting to 0.

At this point, in the php.ini configuration file upload options to configure the PHP tutorial is finished, through the above steps of practice and learning, combined with PHP programs, file Upload function can be achieved.



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.