Uploading large(big) files in PHP using .htaccess

I’ve seen that many of my friends are struggling with the uploads of the bigger or larger files in PHP. After looking at their struggle, i’m here to solve the problem of uploading larger or bigger files in PHP.

Most of the web servers are configured such a way that a user can only upload the maximum file size of 2MB. So there might be the problem for the people who wants to upload the .pdf file of size around 15MB. But, you can increse the maximum upload file size limit by using .htaccess file.

Here is a small tips for you which you can use to upload such a large file using file field of the form and move_uploaded_file() function in PHP.

1) Create a .htaccess file in the root folder of web server.

2) Put the following code in side the .htaccess file and save it.

php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200

Now you can upload the file-size up-to 20MB in a simple way using file field in your html form and move_uploaded_file() function available in PHP. In the above .htaccess file, uploading capability is increased by the four parameter first one is maximum file size for uploading, second one is maximum size of the post data , third one is maximum time in seconds a script is allowed to run before it is terminated by the parser and last one is maximum time in seconds a script is allowed to parse input data such as like file uploads, POST and GET data.

You can change the above parameter to upload the bigger file size than 20MB.

77 thoughts on “Uploading large(big) files in PHP using .htaccess

  1. apple

    Another question, this was regarding localhost. I modify my php.ini already, I increase the upload_max_filesize and post_max_size but then, I cannot upload files more than 2Mb. What do you think guys is the problem? Thanks.

  2. bagan

    Hello roshan, I created .htaccess file in my web root folder and tested phpinfo page. it was not effected the php settings. actually I don’t have own server. I am using webservices. Is this case.? I am looking for your great help to resolve my problem. my webserver has CGI version php. please help me how we could change upload file size limit. Advanced thanks for you and hope my prob would get resolved soon.

  3. balakris

    my server is 7 mb file upload size capacity.is there any possible to upload more than 7 mb with help of htaccess(upload_max_filesize and post_max_size)

  4. Debugging tips for people who are unable to get it to work:

    1) Inside the directory that contains the php file upload handler script, create a php file that contains a call to phpinfo(). Open this file in browser and inspect the “local” values (e.g. upload_max_filesize) reported by phpinfo.

    2) Activate additional error logging in php if possible. If you do not have access to php’s global configuration file, you *might* be able to override settings via .htaccess by aadding these lines:

    # enable sending error message to browser
    php_flag display_errors On
    # shows most errors including NOTICEs
    php_value error_reporting 2047

    3) Have a look at apache error log for errors related to apache, not php. Apache error logs are enabled by default and usually stored in a file called ‘error.log’. This gives you further details about configuration errors such as:

    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.

    4) Try entering numerical values instead of php constants. Example:

    20M => 20971520
    100M => 104857600

  5. WoW. very very thanks. Its working on fine way. Its really a good and easy way.

  6. Chien

    thanks so much! it works!!!!!!!!!!!

  7. not

    bla bla bla, i see no deference, it’s not working at all lol

  8. Bob

    It worked for me but to err on the side of caution (Possible DDOS attacks) I decided to use these same exact settings in the PHP config editor. I tested everything out and it works smoothly now, thank you for sharing this.

  9. SlackeR

    Can you post a same html or php upload script that I can use even a simple one? I tried this on htaccess and created my php upload script. I gave me errors but when I checked it was able to upload the 34mb file I tried uploading

    A nice script even a simple one that is usable would help. Thanks

  10. Kirill

    I have trouble uploading realy large files. Up to 5 GB. I have next entries in my .htaccess, but it doesn’t solve the problem.

    LimitRequestBody 0
    php_value upload_max_filesize 10000M
    php_value post_max_size 15000M
    php_value max_execution_time 18000
    php_value max_input_time -1
    php_value memory_limit -1

    I am able to upload 1.5 GB file, but failed with 4 GB.

    What should I check?

  11. i got 500 internal server erro..
    help please

  12. Nikhil


    hi roshan i’m exactly the same issue. Even after settings the .htaccess file i cannot upload a 17 mb file my phpinfo() says that upload limit is 50 mb and post limit is also 50 mb and the memory limit is 128mb.

    if i use a .htaccess file the script executes for some time and returns a “500 Internal server”
    with out .htaccess file the sever returns “Connection was reset”.

    Is it some thing to do with the exectuion time of the script ? I tried to extend the script execution time thorugh the .htacess[php_value max_execution_time 900].Stil i’m getting
    “500 Internal server” error.
    Please hep i’m new to php coding………


  13. It was quite a hurdle to upload large files. In our line of business, files are always macro, never micro. Your tutorial has made uploading a breeze.

  14. ichha

    Why ini_set() does not work. I want to increase the upload limit.

    Does it depends on PHP version

  15. Ichha

    Why ini_set() does not works.I want to increase the upload limit.
    Does this depends on PHP version

  16. i have uploaded a site ,its a huge with lots of pages more than 200, and lots of folder having files. i am using the filezilla. While using these i am not confirmed that if each file is being uploaded . Is there any way that i should confirm that all the files has been uploaded.

  17. Gangadhara B S

    Its working correctly, great post.
    Thanks a lot Dude

  18. not work !

  19. isabel

    Hi everyone,

    I have the same problem: unable to upload files bigger than 12 MB;
    – I don’t have access to any of the ini-files
    – the hostingprovider tells me it’s not possible to ‘upgrade’ to allow the upload of more MB
    – adapting the .htaccess file with the code provided:
    php_value upload_max_filesize 20M
    php_value post_max_size 20M
    php_value max_execution_time 200
    php_value max_input_time 200
    returns an Internal Server Error: The server encountered an internal error or misconfiguration and was unable to complete your request.
    – only 1 FTP user is available for this account (so I cannot provide this option either)..

    As per the hostingprovider, I have to “split the query in the notepad and then import the files” … is this an option? And if so, HOW do I have to do this?…

    Any help is really appreciated!
    thanks in advance 😉

  20. ichha

    Check what is the server type.If the server is windows server it works with .htaccess file but produces internal server error for the Linux server.

    For this you have to create the custom php.ini file and upload in the root folder.

    Create the php.ini file and put

    upload_max_filesize = 100M
    post_max_size = 100M
    output_buffering = on
    max_execution_time = 1000
    max_input_time = 1000
    memory_limit = 64M

    I think it works.

  21. Ritesh

    @Roshan- do you have any tips for uploading large file very fast.
    I have large 44MB .pdf, .xlsx and .csv. It seems like .csv uploading faster.

  22. Really great, It worked like a charm

  23. Prakash

    Hi Roshan,
    I have tried the “set_time_limit(0);” to increase the execution time but it won’t worked.
    I feel your approach may work by putting it in .htaccess.
    any way thanks, will let you know about it.
    But why couldn’t i set it in .ini (remote server)….????
    ini_set(‘max_execution_time’, 7200); — Working
    ini_set(‘upload_max_filesize’, ’64M’); — Not working
    ini_set(‘max_input_time’, 7200); — Not working
    ini_set(‘memory_limit’, “64M”); — Not working

  24. Prakash

    Hey It’s not working buddy…..
    It is showing 500 Internal Server Error.

Comments are closed.