Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PHP.ini configuration for handling large file upload in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 390
    Comment on it

    PHP provides a friendly environment in case of file uploads but if one wants to upload files greater then 2 Mega Bytes then the default installation of PHP fails.
    But, we can increase the limit when ever necessary.
    This Blog will help you configure your PHP engine for handling such large file transfers.

    To find the location of your php.ini file,you can call the phpinfo() function. It will also tell you the current values for the following settings that we need to modify to increase the limit during file upload

               
    1.file_uploads
    2.upload_max_filesize
    3.max_input_time 
    4.memory_limit
    5.max_execution_time
    6.post_max_size
    

    upload_max_filesize and post_max_size
    The two PHP configuration options that control the maximum upload size are :
    1) upload_max_filesize
    2) post_max_size.
    Both can be set to, say, 10M for 10 megabyte file sizes accordingly.

    memory_limit

    Setting too high memory limit value can cause delay in results or sometimes no results because if several uploads are being concurrently, then all the memory which is available will be used up and consumption of memory might also effect the whole server. We can try,say,
    memory_limit = 32M

    max_execution_time and max_input_time

    In addition, uploading large files/images can also cause script time-outs. We therefore need to set PHPs max_input_time and max_execution_time to something like 300 (5 minutes,it should be specified in seconds).

    NOTE:PHP also provides a set_time_limit() function so you dont need to set max_execution_time directly.

    All these options can be set in your servers php.ini configuration file and then they are applicable to all your applications.

    Alternatively, if youre using Apache, you can configure the settings in your applications .htaccess file.

    The following constraints should be defined within your PHP application,as defined below(example):
    ini_set('upload_max_filesize', '10M');
    ini_set('post_max_size', '10M');
    ini_set('max_input_time', 300);
    ini_set('max_execution_time', 300);

    Since,now you have extended the execution time and increased the file size now your application is expecting a large upload. Other forms/applications where extensions have not been made would revert to the default 30-second time-out and 2MB.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: