Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

PHP Upload: Increase Size

Posted 04 Jun 2002 06:28:19
1
has voted
04 Jun 2002 06:28:19 Andrew Eldon posted:
Hi there,

I have downloaded the PHP upload extension which is fantastic. I've included it in our corporate intranet for people to upload files with, but a 2 MB limit is way too small. I have also downloaded and installed the Increase Size extension, but this only works on a 1 off basis.

I'm new to PHP (so please bear with me) but if Size extension temporarily changes the settings in the php.ini file to allow for 8 MB and then resets itself - could you not change the default settings in the php.ini file to allow for much bigger file sizes? What information would I have to change and is there a Max. file size - I really need to be able to allow users to upload some pretty large files (50MB and up).

I don't know enough to make this happen on my own.

Hope someone can help or clear things up.

Cheers.

Andrew

Replies

Replied 04 Jun 2002 08:59:01
04 Jun 2002 08:59:01 Bruno Mairlot replied:
Hi Andrew,

to be able to increase the upload size, you should edit your php.ini file, and at the line :

upload_max_filesize = 2M

change it to

upload_max_filesize = 50M

But, you must be aware that when you upload a file with PHP, it keeps the whole file in memory before writing it onto the disk, therefore uploading a 50 Mb file will require 50 Mb of RAM on your server. Having three users that simultaneously upload that kind of files could easily bring the server on to its knees.

Bruno
Replied 04 Jun 2002 09:51:55
04 Jun 2002 09:51:55 Andrew Eldon replied:
Hi Bruno,

Thanks for the message: I have been consulting the PHP Manual and have changed the post_max_size, upload_max_size and memory_limit settings in the php.ini file - but unfortunately none of this has worked yet.

I have a feeling it may be another server default that I need to change but my head hurts too much right now to try and figure that one out!

Thanks for the heads up about the RAM usage...I didn't know that - very useful information.

Thanks again,

Andrew
Replied 12 Sep 2003 02:47:24
12 Sep 2003 02:47:24 Kent Livingston replied:

Has this ever been resolved. I was asking this question months ago and it has limited my ability to effectively use the extension because there are a lot of files in the 15-35 Mb size range that need to be uploaded and I have not been able to get it to work...


<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>

Thanks for the message: I have been consulting the PHP Manual and have changed the post_max_size, upload_max_size and memory_limit settings in the php.ini file - but unfortunately none of this has worked yet.

I have a feeling it may be another server default that I need to change but my head hurts too much right now to try and figure that one out!

Thanks for the heads up about the RAM usage...I didn't know that - very useful information.

Thanks again,

Andrew
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 15 Sep 2003 09:10:55
15 Sep 2003 09:10:55 Martha Graham replied:
Replied 15 Sep 2003 16:05:32
15 Sep 2003 16:05:32 Kent Livingston replied:
Th informatio in that post sounds wonderful, but... I read conflicting information about this issue. And empirically speaking - I have safe mode off, and all the other settings mentioned below set correctly and I still have issues with large files not uploading correctly. Will the real answer please stand up... ;-\ ?
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Check this: www.dmxzone.com/forum/topic.asp?TOPIC_ID=24138&FORUM_ID=788&CAT_ID=260&Topic_Title=Max+file+size&Forum_Title=General

Martha Graham
DMXzone manager
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 05 Sep 2007 23:07:35
05 Sep 2007 23:07:35 Scott Haines replied:
Hey Everyone,
I stumbled upon this post trying to find the answers that everyone else is seeking. The problem with the PHP upload is as follows:
1.) The php.ini files need to be have all overrides as talked about before
a.) upload_max_filesize = 50MB
b.) max_execution_time = -1 or 18000 (18000 = 5 hours)
c.) memory = upload_max_filesize

you can do most of the switches on a one time basis like the following:
add to the top of your php file before
-----------------------------------------
ini_set('max_execution_time','18000');
ini_set('upload_max_filesize','50');
init_set('max_input_time','-1'); // -1 is equiv to infinite
ini_set('memory_limit','50');

The code above will switch the settings as you need them switched, however safe_mode must be set to off.
additionally you need to make sure the file_uploads is turned on, as silly as this sounds this is the big problem for a lot of people.

----------------------------------------

This is just the start, there are more variables that need to be switched, like the well known 'keep-active' string parameter. This is usually set to 90 seconds - 300 seconds, so if you override all of PHP's settings, your still stick with a browser time out and most likely a 500 error server response. I have been able to upload a 6MB file using the following code. Maybe I was lucky!

--------------------------------------------------
&lt;?php
ini_set('max_execution_time','10000'); // ten minutes
ini_set("session.gc_maxlifetime", "18000";
session_cache_limiter('private_no_expire');
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Upload Test 50 MB&lt;/title&gt;
&lt;script type="text/javascript" language="javascript"&gt;
// create a function to tell if the file is uploading or error, or finished
function disable(){
var obj = document.getElementById('uploadmes');
var messege = "&lt;p&gt;&lt;font color='#00FF00' size='2'&gt;Preparing File. Please be patient, this process can take around 2 minutes for a 50MB file&lt;/font&gt;&lt;/p&gt;";
obj.innerHTML = messege;
var button = document.getElementById('btn');
var dis = '&lt;input disabled type="button" value="Upload Image" onClick="disable();" tabindex="2"&gt;';
button.innerHTML = dis;
}

function update(){
var obj = document.getElementById('uploadmes');
var messege = "&lt;p&gt;&lt;font color='#00FF00' size='2'&gt;Uploading File. Please wait.&lt;/font&gt;&lt;/p&gt;";
obj.innerHTML = messege;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="uploadmes"&gt;&lt;/div&gt;
&lt;?php
switch($_REQUEST['req']){
default:
?&gt;
&lt;h4&gt;Please Upload your image &lt;span style="font-size:10px"&gt;&nbsp;&nbsp;&nbsp;image must be less than 50 MB for web based uploads&lt;/span&gt;&lt;/h4&gt;
&lt;br&gt;
&lt;div id="formstuff" style="border:1px solid #000000; padding:10px;"&gt;
&lt;form id="upload_file" action="&lt;?=$_SERVER['PHP_SELF']?&gt;" method="post" enctype="multipart/form-data"&gt;
&lt;input type="hidden" name="MAX_FILE_SIZE" value="524288000" /&gt;
&lt;input type="file" name="image" tabindex="1" size="35" /&gt;
&lt;input type="hidden" name="req" value="upload"&gt;
&lt;span id="btn"&gt;&lt;input type="button" value="Upload Image" onClick="disable(); submit();" tabindex="2"&gt;&lt;/span&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;?php
break;

case "upload":
# set constant
?&gt;
&lt;script type="text/javascript" language="javascript"&gt;
function meswrite(mes){
var obj = document.getElementById('uploadmes');
var messege = "&lt;p&gt;&lt;font color='#00FF00' size='2'&gt;"+mes+"&lt;/p&gt;";
obj.innerHTML = messege;
}

window.onLoad = meswrite('Uploading File. Please wait.');
&lt;/script&gt;
&lt;?php
define ("FILES","./uploads/";
$name = $_FILES['image']['name'];
$size = $_FILES['image']['size'];
/*Make sure the file was posted */
if(is_uploaded_file($_FILES['image']['tmp_name'])){
/* move uploaded image to final destination. */
$result = move_uploaded_file($_FILES['image']['tmp_name'], FILES."/$name";
if($result == 1) {
?&gt;
&lt;script type="text/javascript" language="javascript"&gt;
meswrite('File uploaded to server. An email is on its way to you to confirm your order');
&lt;/script&gt;
&lt;?php
echo '&lt;p&gt;&lt;img src="./uploads/'.$_FILES['image']['name'].'" border="0" alt="'.$name.'" /&gt;&lt;/p&gt;';
} else {
echo "&lt;p&gt;The file didn't upload correctly. Please either try again, or contact us for an FTP account to upload your file via FTP.&lt;/p&gt;";
}
}

break;
}
?&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------
As long as you CHMOD the uploads folder to 777 (read,write,execute) you should be all set for up to 6MB uploads. The browser specific functions get squirrelly after that. Also if you noticed, the uploads path, as in the define("FILES",) area of the script has a './uploads/', it is critical to have the period before the forward slash, this helps the uploads function work on a lot of non-standards compliant browsers, and has saved me the frustration of getting this to work any other way. This tells the server to look for the file inside the directory (.), and make sure that it stems (/) from that directory into a folder called 'uploads/' - the alternative is just 'uploads/' and that will throw an error almost every time.

I hope this helps someone, and if anyone has found a way to trick the keep-alive to infinite please post a nice reply, I've tried
ini_set("session.gc_maxlifetime", "18000";
session_cache_limiter('private_no_expire');

but the server still times out and/ or throws an error with a 8MB file, and forget the actual 50MB file, as they said before, this could have the server come crashing down, and FTP is a better alternative, as it is a progressive upload, and not the entire 50MB at one time.

- Scott Haines
www.newfrontproductions.com

Reply to this topic