...

View Full Version : File upload fails when too large



madmatter23
03-02-2008, 01:40 AM
This is strange. I have a script that allows a user to update a 'show' database entry by attaching a video file to it.

It works fine with a 5mb file, but it fails with a 14mb file. The max file size is set to 400000000 bytes, about 38mbs. My host informs me that there is no maximum limit placed on user file uploads (I host with bluedomino.com).

The most confusing part about the failure is the error message that it generates. Instead of a server error, file size error, or even the message that I have set for !move_uploaded_file, I get this error "Error: command '' unknown".

Now you're going to have to look at my code to understand why that's so strange. Here's the condensed version.

The form page:


echo "<br><form name=showform action=\"../ttadmin/admin_show.php?action=update" method=\"post\" enctype=\"multipart/form-data\"> \n";
echo "<p>Category: <input name=f4 type=text size=50 value=".$category.">\n";
echo "<p>Upload new audio? <input type=\"checkbox\" name=\"audiocheck\" value=\"checked\"></p> \n";
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"40000000\">";
echo "<p>Audio File:<input type=\"file\" name=\"audio\"></p>\n";
echo "<p>Upload new video? <input type=\"checkbox\" name=\"videocheck\" value=\"checked\"></p> \n";
echo "<p>Video File:<input type=\"file\" name=\"video\"></p>\n";
echo "<br><input name=\"action\" value=\"update\" type=\"hidden\">\n";
echo "<br><input type=\"submit\" value=\"Update Data\" name=\"submit\">\n";
echo "<input type=\"reset\" name=\"reset\">\n";
echo "<input type=\"button\" value=\"Cancel\" onclick=\"history.back()\">\n";
echo "</form>";/**/
echo "<br /><br /> ** Please only click submit once. If you are uploading files, it may take up to 15 minutes for the update to complete.";


the uploading script:


$action = trim(strip_tags($_GET["action"]));
switch ($action) {
case "update":
echo "debug: \$action = $action";

$query = "update $showtable set topic ='$f0',showdate='$f1',starttime='$f2',endtime='$f3',moduser='$mod',category='$f4'";

if ($_POST['videocheck'] == "checked"){
echo "VIDEO UPDATE";
if (isset($_FILES['video']) && $_FILES['video']['name'] != ""){

$video = $_FILES['video']['name'];

if (!preg_match('/swf/',$video)){
die ("Error: Your uploaded file must in .swf format. Other file types are not allowed<br /> Your file must not exceed 38mb in size.");
}

$target_folder = $_SERVER['DOCUMENT_ROOT']."/show_video/";
$target_path = $target_folder.basename($_FILES['video']['name']);
$SQLVideoPath = "show_video/".basename($_FILES['video']['name']);

if(move_uploaded_file($_FILES['video']['tmp_name'], $target_path)) {
chmod("$target_path",0777);
echo "The file ".basename($_FILES['video']['name'])." has been uploaded!<br><br>";
$video_path = $target_path;
$video_path = stringCheck($video_path);
$query = $query.",video='$SQLVideoPath'";
$VIDEO = TRUE;
}

else{
echo "There was an error uploading the file, please try again!";
}
}
}

$query = $query." WHERE $pkshow = $id";

echo $query;
mysql_query($query) or die(mysql_error());
echo "<br>The show information has been updated.";
break;
default:
echo "Error: command <b>'".$action."'</b> unknown";
break;
}



Ok so again, I'm getting the error "Error: command '' unknown." To me this indicates that it didn't receive the GET variable $action, which should equal "update" and cause the case "update" code to execute.

But... I know that my code does relay that variable. It works with a small file! How could a larger file throw that off? It doesn't make any sense to me.

I'd really appreciate any help that could be offered. Ideas, advice, answers, etc. Thanks a lot!

eak
03-02-2008, 03:09 AM
setting MAX_FILE_SIZE in a hidden input field is really use less, at least to me. I rarely use it.


A host always has an upload limit, especially if they are shared hosting.
try putting this in an .htaccess file to try setting it your self.
It must be in an .htaccess file (or the servers httpd.conf). Trying this using ini_set will not work since the the file will have already been uploaded before the php script is executed.


php_value upload_max_filesize 100M
php_value post_max_size 105M
php_value memory_limit 50M

also try this in a php page


<?php
echo ini_get('upload_max_filesize');
echo ini_get('post_max_size');
echo ini_get('memory_limit');
?>

madmatter23
03-02-2008, 06:16 AM
aha, I put this code:


<?php
echo ini_get('upload_max_filesize');
echo ini_get('post_max_size');
echo ini_get('memory_limit');
?>


onto a php page and got the result "10M 11M 12M"

I guess that my hosting service lied to me. Maybe I can get them to change the quota.

Thanks a lot for the tip, I would have wasted a lot of time scouring my code otherwise.

I created an .htaccess file with just


php_value upload_max_filesize 100M
php_value post_max_size 105M
php_value memory_limit 50M


in it, but it causes an internal server error once uploaded. Do I have to use any additional formatting?

eak
03-02-2008, 08:31 AM
are you using 1and1? I have some work sites there and their servers do the same thing.

You should take it out of your .htaccess file and try this.


upload_max_filesize 100M
post_max_size 105M
memory_limit 50M

Save that as php.ini - place root folder of website.

I don't know if that will work for you, but it is worth a shot.

digitalfiz
03-02-2008, 10:26 AM
You might also be able to use ini_set() to set the values. Depends on your host. The php.ini ideas works well on cpanel servers too.

eak
03-02-2008, 05:26 PM
to quote myself...


It must be in an .htaccess file (or the servers httpd.conf). Trying this using ini_set will not work since the the file will have already been uploaded before the php script is executed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum