Solved

php upload timeout firefox

Posted on 2012-04-03
12
313 Views
Last Modified: 2012-04-27
I have an uploader setup in Codeigniter , it is for large file uploads i have put
 ini_set('upload_max_filesize', '125M');  
    ini_set('post_max_size', '125M');  
    ini_set('max_input_time', 6000);  
    ini_set('max_execution_time', 6000);  
      ini_set('memory_limit','1200M');

its working fine in chrome, uploading file and going to next window.
in FF it is going till 98% and the logs out of admin section.


any idea what might be the problem ??
0
Comment
Question by:codeoxygen
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 7

Expert Comment

by:ZShaver
ID: 37802700
i would use set_time_limit(6000);

maybe you're exceeding the script time execution limit

Also, a very critical flaw in your posted code is that you CANNOT change upload_max_filesize or post_max_size at runtime. Those two lines of your script will have 0 effect.  The data gets submitted to PHP before the script even runs, so setting it in the script does not work at all. You MUST define this in php.ini (or you can also accomplish this in a .htaccess file or the main config file if using apache).
0
 
LVL 7

Expert Comment

by:ZShaver
ID: 37802774
Actually, more likely it has to do with character sets and encoding. E.g. if you submit in UTF-8, and your filename of the file is in UTF-16 because it has unicode characters, the filename will get garbelled, so you would either have to:

try removing the character set definition from your html <form> tag
OR process the filename in the PHP side before it is handled to convert the character set back into what it should be
0
 

Author Comment

by:codeoxygen
ID: 37802795
so then why is it working fine in chrome and not in FF ??
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 7

Expert Comment

by:ZShaver
ID: 37803377
no idea, but when i was investigating the and looking up stuff on google other people were saying that it happens in firefox and not safari. people fixed it by removing the UTF-8 thing or by processing the filename variable upon receipt. the data isn't getting corrupted, it's just an issue with the filename variable due to the charset encoding type.
must be different ways that the browsers interpret the form data, compile it into a package, and submits the request to the web server.
0
 
LVL 7

Expert Comment

by:ZShaver
ID: 37803401
to confirm try echoing the filename to your web browser in the upload script and see if it gives garbage or the proper filename
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37804143
try specifying the encoding in your form tag, like this:

<form enctype="multipart/form-data">

Open in new window

0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37804152
...if you submit in UTF-8, and your filename of the file is in UTF-16 because it has unicode characters...
Notice that the above statement is innacurate, as UTF-8 is Unicode.
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37804163
...but zshaver is absolutely right in regard to ini-setting...
0
 
LVL 9

Expert Comment

by:rinfo
ID: 37805493
Have you checked dom.max_script_run_time in firefox configuration .
        Type about:config in Firefox’s address bar.
        Filter down to the value for dom.max_script_run_time.
        Change the value to something higher than the default (which is 5.) I set mine to 20.
 and setting it to 0 will result in unlimited max_script_run_time.

basically this script_run_time sets an interval for for firefox to check for no activity on browser if this is so it should pop up an error for unresponsive script and wait for user response.

The above coupled with setting upload max filesize and max execution time should see you
through the problem.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37805622
You might try installing this script and running it (you'll need to change the target directory, etc., but those changes should be pretty obvious if you read the code near the top).  PHP will give you lots of information if you look at the return values from functions, look at error codes, etc.  Give it a try and please post back if you still find that you're stuck.
<?php // RAY_upload_example.php
error_reporting(E_ALL);


// MANUAL REFERENCE PAGES YOU MUST UNDERSTAND TO UPLOAD FILES
// http://php.net/manual/en/features.file-upload.php
// http://php.net/manual/en/features.file-upload.common-pitfalls.php
// http://php.net/manual/en/function.move-uploaded-file.php
// http://php.net/manual/en/reserved.variables.files.php

// MANUAL PAGES THAT ARE IMPORTANT IF YOU ARE DEALING WITH LARGE FILES
// http://php.net/manual/en/ini.core.php#ini.upload-max-filesize
// http://php.net/manual/en/ini.core.php#ini.post-max-size
// http://php.net/manual/en/info.configuration.php#ini.max-input-time


// PHP 5.1+  SEE http://php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY (MUST ALREADY EXIST)
$uploads = 'RAY_junk';

// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT - ABOUT 8 MB
$max_file_size = '8000000';

// ESTABLISH THE MAXIMUM NUMBER OF FILES WE CAN UPLOAD
$nf = 3;

// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
$file_exts = array
( 'jpg'
, 'gif'
, 'png'
, 'txt'
, 'pdf'
, 'mp3'
)
;

// LIST OF THE ERRORS THAT MAY BE REPORTED IN $_FILES[]["error"] (THERE IS NO #5)
$errors = array
( 0 => "Success!"
, 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini"
, 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"
, 3 => "The uploaded file was only partially uploaded"
, 4 => "No file was uploaded"
, 5 => "UNDEFINED ERROR"
, 6 => "Missing a temporary folder"
, 7 => "Cannot write file to disk"
)
;




// IF THERE IS NOTHING IN $_POST, PUT UP THE FORM FOR INPUT
if (empty($_POST))
{
    ?>
    <h2>Upload <?php echo $nf; ?> file(s)</h2>

    <!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        ENCTYPE IN THE HTML <FORM> STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
        ABSENCE OF ACTION= ATTRIBUTE IN FORM TAG CAUSES POST TO SAME SCRIPT
    -->

    <form name="UploadForm" enctype="multipart/form-data" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php // CREATE INPUT STATEMENTS FOR UP TO $n FILE NAMES
    for ($n = 0; $n < $nf; $n++)
    {
        echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
    }
    ?>

    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <strong>overwrite</strong> existing files.
    <input type="submit" value="Upload" />
    </form>
    <?php
    die();
}
// END OF THE FORM SCRIPT



// WE HAVE GOT SOMETHING IN $_POST - RUN THE ACTION SCRIPT
else
{
    // THERE IS POST DATA - PROCESS IT
    echo "<h2>Results: File Upload</h2>\n";

    // ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
    // echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>\n";

    // ITERATE OVER THE CONTENTS OF $_FILES
    foreach ($_FILES as $my_uploaded_file)
    {
        // SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
        $error_code = $my_uploaded_file["error"];
        if ($error_code == 4) continue;

        // SYNTHESIZE THE NEW FILE NAME
        $f_type    = trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
        $f_name    = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
        $my_new_file
        = getcwd()
        . DIRECTORY_SEPARATOR
        . $uploads
        . DIRECTORY_SEPARATOR
        . $f_name
        . '.'
        . $f_type
        ;
        $my_file
        = $uploads
        . DIRECTORY_SEPARATOR
        . $f_name
        . '.'
        . $f_type;

        // OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
        if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");

        // IF THERE ARE ERRORS
        if ($error_code != 0)
        {
            $error_message = $errors[$error_code];
            die("Sorry, Upload Error Code: $error_code: $error_message");
        }

        // GET THE FILE SIZE
        $file_size = number_format($my_uploaded_file["size"]);

        // IF THE FILE IS NEW (DOES NOT EXIST)
        if (!file_exists($my_new_file))
        {
            // IF THE MOVE FUNCTION WORKED CORRECTLY
            if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
            {
                $upload_success = 1;
            }
            // IF THE MOVE FUNCTION FAILED
            else
            {
                $upload_success = -1;
            }
        }

        // IF THE FILE ALREADY EXISTS
        else
        {
            echo "<br/><b><i>$my_file</i></b> already exists.\n";

            // SHOULD WE OVERWRITE THE FILE? IF NOT
            if (empty($_POST["overwrite"]))
            {
                $upload_success = 0;
            }
            // IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
            else
            {
                $now    = date('Y-m-d');
                $my_bak = $my_new_file . '.' . $now . '.bak';
                if (!copy($my_new_file, $my_bak))
                {
                    echo "<br/><strong>Attempted Backup Failed!</strong>\n";
                }
                if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
                {
                    $upload_success = 2;
                }
                else
                {
                    $upload_success = -1;
                }
            }
        }

        // REPORT OUR SUCCESS OR FAILURE
        if ($upload_success == 2) { echo "<br/>It has been overwritten.\n"; }
        if ($upload_success == 1) { echo "<br/><strong>$my_file</strong> has been saved.\n"; }
        if ($upload_success == 0) { echo "<br/><strong>It was NOT overwritten.</strong>\n"; }
        if ($upload_success < 0)  { echo "<br/><strong>ERROR: $my_file NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</strong>\n"; }
        if ($upload_success > 0)
        {
            echo "$file_size bytes uploaded.\n";
            if (!chmod ($my_new_file, 0755))
            {
                echo "<br/>chmod(0755) FAILED: fileperms() = ";
                echo substr(sprintf('%o', fileperms($my_new_file)), -4);
            }
            echo "<br/><a target=\"_blank\" href=\"$my_file\">See the file $my_file</a>\n";
        }
    // END FOREACH ITERATOR - EACH ITERATION PROCESSES ONE FILE
    }
}

Open in new window

0
 

Author Comment

by:codeoxygen
ID: 37812897
Ray, your code works fine in FF.
but my problem, is I am using upload progress module to show a progress bar in CI
it goes upto 99% file also gets uploaded and then to login page
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37812967
Well, I can't do much about CI, but at least you know that the upload process works.  So your server is probably A-Ok.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question