1

You have a web page with a form that has an input field of type file. You have another web page that expects the data from the first page.

In the second page you need to check whether a file has been sent.

How do you do that?

I've been using the following statement but I'm not sure about it:

$_FILES["file"]["tmp_name"] == ""

4 Answers 4

2
  • http://www.w3schools.com/php/php_file_upload.asp

    <?php
    if ($_FILES["file"]["error"] > 0)
    {
        echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
    ?>
    
Sign up to request clarification or add additional context in comments.

Comments

1

Try array_key_exists("file", $_FILES)

Comments

0

I don't work with PHP file uploads often, but is there any reason that:

isset($_FILES['file'])

won't do the trick?

Comments

0

Or you could just check if $_FILES is empty.

if(empty($_FILES))
{
return false; // or make something else
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.