Problem with uploading large files - over 2mg

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
CAN007
Forum Newbie
Posts: 9
Joined: Fri Jun 06, 2003 2:00 pm
Location: Toronto, Ontario, Canada

Problem with uploading large files - over 2mg

Post by CAN007 »

I need to have files uploaded upto say 20Mg. I have put this small test script together to simplify, and to try and solve this problem.

The test files I have been using are 4-6Mg... all other files, >2Mg work fine.

Any suggestions?
----------------------------------------------
<?php ini_set('upload_max_filesize','20M'); ?>
<html>
<head>
<body>
<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="20000000">
File: <input name="userfile" type="file" /><br />
<input type="submit" value="Upload" />
</form>

<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "files/" . $_FILES["userfile"]["name"]);
echo "<p>File uploaded successfully.</p>";
}
?>
</body></html>
-----------------------------------
Thanks,
James
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You need to change the upload_max_filesize in the php.ini, ini_set() will have no effect on it because the file's already been passed to PHP before the ini setting is changed.

http://php.net/ini_set

Mac
User avatar
CAN007
Forum Newbie
Posts: 9
Joined: Fri Jun 06, 2003 2:00 pm
Location: Toronto, Ontario, Canada

php ini?

Post by CAN007 »

Is this to be set on the server? Im not quite following you here.

Where would I locate php.ini?
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post by Galahad »

In Linux (and probably Unix systems too), it is "/etc/php.ini" on the server. I believe you also have to change an apache config variable that limits the max request size, though. I hope you run your own server.
User avatar
CAN007
Forum Newbie
Posts: 9
Joined: Fri Jun 06, 2003 2:00 pm
Location: Toronto, Ontario, Canada

Post by CAN007 »

Just this afternoon I realized that you would assume that I did run my own server... however, I do not... I contacted the host today, and they seem reluctant to do this request, however, we shall see.

Will let you know. :)

James
User avatar
CAN007
Forum Newbie
Posts: 9
Joined: Fri Jun 06, 2003 2:00 pm
Location: Toronto, Ontario, Canada

Post by CAN007 »

Found you can alter the php.ini values in the .htaccess in the root directory... got it over 2Mg, but now Ive hit the hurdle of 8Mg.

ini_set('upload_max_filesize','50M');
ini_set('post_max_size','55M');
ini_set('max_execution_time','60');
ini_set('memory_limit','50M');

I have tried the above values in the .htaccess as well... but still not able to get over 8Mg.

Any ideas?

Thanks, James
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post by Galahad »

Like I said before, I believe that you have to change an apache configuration variable. Look on this page for a description of "LimitRequestBody". They even mention it limiting file upload size.
User avatar
CAN007
Forum Newbie
Posts: 9
Joined: Fri Jun 06, 2003 2:00 pm
Location: Toronto, Ontario, Canada

Post by CAN007 »

I dont blieve I can adjust the server, as I do not host the site.... wherein, the problem lies.

I have sent an email to the host to request this, however, I do not think they want to change a global setting...

I hope I am incorrect on both counts... or either one will do! :)
Post Reply