• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 851
  • Last Modified:

Firefox and file uploads

I'm using the following code to try to upload images via firefox.

<?
//The data encoding type, enctype, MUST be specified as below

echo "<form enctype=\"multipart/form-data\" action=\"sendfile.php\" method=\"POST\"
>";

//MAX_FILE_SIZE must precede the file input field -->";
echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1048576\" />";

//Name of input element determines name in $_FILES array
echo "Send this file: <input name=\"userfile\" type=\"file\" />";
echo "<input type=\"submit\" value=\"Send File\" />";
echo "</form>";
?>

then in sendfile.php I have...

<?php

$uploaddir = '/home/web/site/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
echo $uploadfile . "<br>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>

It works fine in internet explorer but it fails in firefox.  In firefox the output of the debugging info looks like this.

/home/web/site/uploads/correctimage.jpg
Possible file upload attack!
Here is some more debugging info:Array
(
    [userfile] => Array
        (
            [name] => correctimage.jpg
            [type] =>
            [tmp_name] =>
            [error] => 2
            [size] => 0
        )

)

How can I lookup what the error means and what is the problem?
0
serjosh
Asked:
serjosh
1 Solution
 
Muhammad WasifCommented:
This is PHP code and run on server not on the client side. I tested this code in Firefox and its working fine with me.

Look at the debug info, if the file had uploaded it must have some value in tmp_name. Its mean file is not uploaded.

(
    [userfile] => Array
        (
            [name] => correctimage.jpg
            [type] =>
            [tmp_name] =>
            [error] => 2
            [size] => 0
        )

)

Are you using the same file to upload in both browsers?
0
 
serjoshAuthor Commented:
it is the exact same file and I've tried many different files, all relatively small, IE always works and firefox doesnt.    

DOH!  I just figgured it out.  For some odd reason all I had to do was restart firefox and it then worked *shrug*
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now