PHP File upload You must know a few _php tips

Source: Internet
Author: User
Tags 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 upload_tmp_dir,upload_max_filesize,post_max_size and other options, The following one by one explains.

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 configurationupload_max_filesizeandpost_max_sizeTwo 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.
Defaultupload_max_filesize = 2M, that is, file upload size of 2M, if you want to upload more than 8M of files, such as 20M, you must setupload_max_filesize = 20M
But the light setting upload_max_filesize = 20M still cannot realize the upload function of the large file, you must modify the php.ini configuration filepost_max_sizeoption that represents the maximum byte length for the data that is 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 to be greater than the value of the upload_max_filesize directive.I normally 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 feel, when more than a certain time, will report the script execution more than 30 seconds of error, because in the php.ini configuration fileMax_execution_timeThe configuration options are in mischief, representing the maximum allowable execution time (in seconds) for each script, and 0 means there is 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.

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.