View previous topic :: View next topic |
Author |
Message |
eyn -
Joined: 11 Sep 2004 Posts: 32 Location: Canada
|
Posted: Sat Mar 19, 2005 6:07 am Post subject: Upload hang for large files |
|
|
Code: | <?PHP
$uploadNeed = $_POST['uploadNeed']; //you need to create a form that sends this POST variable together with filename
define("MEGA",1048576);
define("KILO",1024);
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'.$x]['name'];
$file_size = $_FILES['uploadFile'.$x]['size'];
$file_type = $_FILES['uploadFile'.$x]['type'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],"uploads/$file_name");
// let file_name = "file" if there is no file
if($file_name=="")
$file_name="file";
// handling file size
if ($file_size > MEGA)
{
$file_size = round(($file_size / MEGA),2);
$unit = "mb";
}
elseif ($file_size > KILO)
{
$file_size = floor($file_size / KILO);
$unit = "kb";
}
else
$unit = "b";
// check if successfully copied
if($copy)
{
echo "<P><SPAN class=\"caption\">Name:</SPAN> $file_name<BR>";
echo "<SPAN class=\"caption\">Size:</SPAN> $file_size $unit<BR>";
echo "<SPAN class=\"caption\">Type:</SPAN> $file_type</P>";
}
else
echo "<P>Sorry, $file_name could not be uploaded!</P>";
} // end of loop
?>
|
I used the script above to handle my uploads. But when the filesize exceeds around 9mb, the whole script will hang, for which I do not know what's the problem. Obviously it is not the maximum file size limit as I already set the limit to 100M in the php.ini. Even if there is a limit, the script will just return "file could not be uploaded" as copy function fails.
Can someone kind enough to try this script out on your abyss server? You should finish uploading a huge file within seconds, if the script doesn't hang on you for files over 9mb. Please tell me what's wrong with my script. Thank you.
P.S. This is a self modded script I obtain from some PHP website, i.e. I do not write this from scratch. |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Sat Mar 19, 2005 11:12 am Post subject: |
|
|
It may be that you do not have enough RAM on the PC running abyss? I had a similar problem when I ran a server with only 32mb RAM.
Andy (aka The Inquisitor) _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
admin Site Admin
Joined: 03 Mar 2002 Posts: 1295
|
Posted: Sat Mar 19, 2005 1:58 pm Post subject: Re: Upload hang for large files |
|
|
eyn,
The problem seems to be related to your php.ini configuration. When your upload a file using a PHP script, PHP will create a temporary file where the data will be stored. If there is no more space on yoru harddrive, this kind of errors can occur.
In php.ini, check that upload_tmp_dir is set to a directory where you have enough space. For example, if you set:
Code: |
upload_tmp_dir ="e:\temp"
|
then E: should have at least 100 MB of free space to be able to upload large files.
Do not forget also to set upload_max_filesize to a large value (greater than 100 MB).
There are also another important parameters that you should also set to allow large uploads: max_input_time, memory_limit, max_execution_time, and post_max_size. You can find more information about all this in the excellent article in http://www.radinks.com/upload/config.php .
By the way, do not forget to increase the value of CGI Timeout in Abyss Web Server. |
|
Back to top |
|
|
eyn -
Joined: 11 Sep 2004 Posts: 32 Location: Canada
|
Posted: Sat Mar 19, 2005 8:47 pm Post subject: |
|
|
Thanks admin! The article is really helpful. The problem boils down to the "post_max_size", as php default configuration is 8M, thus the script hangs when I try to upload files larger than 8MB. I thought you only need to configure the "upload_max_filesize", but obviously I'm wrong and there's more configuration to change before it works. I changed the timeout as well as the upload might takes a while if the filesize is large. Thanks! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|