Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    Maryland, USA
    Posts
    165
    Thanks
    12
    Thanked 0 Times in 0 Posts

    File upload fails when too large

    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:
    PHP Code:
    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:
    PHP Code:
    $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!
    Last edited by madmatter23; 03-02-2008 at 12:44 AM.

  • #2
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    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.

    Code:
    php_value upload_max_filesize 100M
    php_value post_max_size 105M
    php_value memory_limit 50M
    also try this in a php page

    Code:
    <?php
    echo ini_get('upload_max_filesize');
    echo ini_get('post_max_size');
    echo ini_get('memory_limit');
    ?>
    Last edited by eak; 03-02-2008 at 02:12 AM.
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • Users who have thanked eak for this post:

    timgolding (03-05-2008)

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    Maryland, USA
    Posts
    165
    Thanks
    12
    Thanked 0 Times in 0 Posts
    aha, I put this code:
    PHP 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
    Code:
    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?
    Last edited by madmatter23; 03-02-2008 at 05:21 AM.

  • #4
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    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.

    Code:
    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.
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."

  • #5
    New Coder
    Join Date
    Mar 2008
    Location
    Lakeland, FL
    Posts
    39
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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.

  • #6
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    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.
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •