PDA

View Full Version : File upload causing slow script warning


misterx
08-09-2006, 02:43 PM
I've made a PHP script for uploading files to the web server. The script itself seems to work fine but it causes FireFox to warn me about how long the script is taking.

When I tested uploading a 1.6 meg file I had to click the 'Continue' button on the script warning about 7 times. I know that I can change the config in FireFox to increase the script warning time limit but I'm wondering if there's something I can do on the PHP side of things to keep it from doing that. The current code is really simple, I've posted it's pieces below.


$FileName = $_FILES['file']['name'];
$fileSource = $_FILES['file']['tmp_name'];

// Make the dir if it isn't already there
if( $FileName ) {
if( !file_exists(FILE_DIR.$FormID) ) {
mkdir( FILE_DIR.$FormID );
}
}

// Move the file to the right place
$destination = FILE_DIR.$FormID."/".$FileName;
if( $fileSuccess = move_uploaded_file( $fileSource, $destination ) ) {
// Update the database upon success of moving the file
$fileString = "INSERT INTO qaFiles VALUES( null, $FormID, '$FileName' )";
mysql_query( $fileString );
}


Hmm, some of that code is irrelevant but you get the idea. In fact, I don't think it's the code that's causing FireFox to freak out at all. It would have to be the part right before this code is executed when the file is actually being uploaded. Still, I'm open to any ideas.

NancyJ
08-09-2006, 02:48 PM
slow script warnings are usually cause by javascript - not php scripts - which are run on the server and are non of your browsers concern

misterx
08-09-2006, 02:57 PM
slow script warnings are usually cause by javascript - not php scripts - which are run on the server and are non of your browsers concern

Are you suggesting that the solution to this problem is to incorporate some javascript?

NancyJ
08-09-2006, 02:59 PM
no, I'm suggesting your problem may be caused by javascript running on the page - not by php. I have scripts that take hours to run and have no problem in firefox, and I have uploaded much bigger files than 1.8mb, never had a single script warning.
I do get those warnings when I accidentally throw javascript into an infinate loop tho

misterx
08-09-2006, 03:22 PM
no, I'm suggesting your problem may be caused by javascript running on the page - not by php. I have scripts that take hours to run and have no problem in firefox, and I have uploaded much bigger files than 1.8mb, never had a single script warning.
I do get those warnings when I accidentally throw javascript into an infinate loop tho

Well the javascript wasn't causing any issues before I added file uploads but I removed it all and retested anyway just to see. Unfortunately I got the same results. There aren't any issues with smaller files like images or text files, but anything larger and I'm bound to see the warning. I suppose it could be the version of FF we have here at my work, unfortunately I don't have permissions to upgrade it myself.