Firefox and file uploads

Posted on 2006-04-12
Last Modified: 2013-12-12
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...


$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 "</pre>";


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

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?
Question by:serjosh
    LVL 20

    Accepted Solution

    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?

    Author Comment

    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*

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now