PHP - How to increase file upload max size?

Posted on 2011-04-20
Last Modified: 2012-05-11
Hi experts, I'm trying to do a simple file upload and I can't upload any file that is greater then 2MB. I did a phpinfo() and below is what I get:

upload_max_filesize = 30M

I even tried with PHP:

ini_set('upload_max_filesize', '10M')
ini_set('post_max_size', '10M')
Question by:infernothao
    LVL 9

    Assisted Solution

    If its taking some time to upload, you may need to increase the max allowed script run time.
    LVL 26

    Assisted Solution


    Author Comment

    Hi guys, both good info. I try uploading a file with 2+ MB on another server and it works.

    --- Working Server ---
    memory_limit = 128M
    post_max_size = 250M
    upload_max_filesize = 250MB
    max_execution_time = 30
    max_input_time = -1

    --- NOT Working Server ---
    memory_limit = 128M
    post_max_size = 40M
    upload_max_filesize = 30MB
    max_execution_time = 30
    max_input_time = 60

    The thing I don't get is that both server have more then enough memory to upload around 2MB. Anyway I attached the actual php script to do the simple upload.

    function uploadImage($fileName, $prefixName="attach_file_"){
    	//Name file by date & timestamp
    	$name = date("Y-m-d-H-i-s"); 
    	//NOTE: This allow user to name the file whatever and it will keep the file type
    	$target = $uploadDir.$name.strrchr($_FILES[$fileName]['name'], '.');
    	if($_FILES[$fileName]['name'] && move_uploaded_file($_FILES[$fileName]['tmp_name'], $target)){
    		return true;
    	return false;
    	<form action="" method="POST" enctype="multipart/form-data">
    		<input type="file" name="attachFile" id="attachFile" />
    		<input type="submit" value="Upload File">

    Open in new window

    LVL 48

    Accepted Solution

    Have you checked the error-code of the upload?
    Add the part from see why the upload failed.
    LVL 9

    Expert Comment

    What version of PHP?  There are bugs associated with max_input_time.

    You might change that option to match the "working" server and see if that makes any difference for you.

    Author Comment

    Thanks guys. Hernst42 comment was helpful. The error was "Failed to write file to disk". After some more time digging around. It turns out that the "upload_tmp_dir" wasn't assigned. So it uses the default directory "/tmp". I checked the linux memory and "/tmp" is set to use only 1MB. So to fix it, I assign the upload_tmp_dir to somewhere else where it allow more memory. Thanks for all the help guys.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now