You are on page 1of 1

Open Source Varsity

Optimize PHP To Handle Large File Uploads


Though PHP presents a very versatile and user friendly interface for handling file uploads, the default installation is not geared for working with file uploads in excess of 2 Megabytes. The following tutorial will help you configure your PHP engine for handling much larger file transfers. There are two factors to be considered prior any file upload. These are: 1. Execution time 3. File Size. All file upload, configuration settings, for a PHP installation are contained in the php.ini file. File uploads are affected by the following PHP settings. file_uploads = On This setting must be on. It allows running uploads through HTTP. Ensure this value is On. The value can be On/Off or 1/0 or true/false. NOTE: If the value is set to Off or 0 or false File uploads will not be permitted upload_max_filesize = 20M This value limits the upper limit, of file size for any file being uploaded. Give it a value that you desire for your specific file upload requirement. The default value is 2M. post_max_size = 40M This value limits the size of all uploaded content. NOTE: upload_max_filesize is for single file. Hence, if we upload 3 files simultaneously, each 15Mb, for a total 45Mb this will fail. Remember post_max_size must be larger, roughly about 40% more than the upload_max_filesize. max_execution_time = 30 Generally image uploads consume a lot of time and resources on a web server. So processing large files may exceed 30 seconds. You can modify this value to whatever your requirements are. When a script execution time exceeds this limit, the server will stop the script or give a fatal error. memory_limit = 128M Generally image uploading consumes a lot of time and memory on a web server. When the image upload exceeds the memory specified, the web server stops executing the script. Then an empty page is displayed or there is no response from the web server or the web server delivers a fatal error. NOTE: It's important to realize that upload_max_filesize is the sum of the sizes of all the files that are being uploaded. For example, to increase the limit on uploaded files to 10 MB: upload_max_filesize = 10M post_max_size = 20M memory_limit = 128M max_execution_time = 50

Open Source Varsity. All Rights Reserved.

You might also like