0

My php upload script works great and is validated for everything from file type to size except if no file exists. You can just hit the submit button and it will send blank data to the upload script. I was trying this:

if (!is_uploaded_file($HTTP_POST_FILES['ufile1']['name']))
{
        header("location:../index.php?code=no_file");
}

It won't work :(

Any way of getting this to work? -mike

2 Answers 2

3

Check the error code:

http://www.php.net/manual/en/features.file-upload.errors.php

if ($_FILES['ufile1']['error'] == UPLOAD_ERR_NO_FILE) { /* no file */ }

Note that you should already be checking the error code to make sure that it's UPLOAD_ERR_OK on files that you actually acccept.

Also, $HTTP_POST_FILES is deprecated in favour of $_FILES these days. That signifies to me that you probably want to find a newer tutorial.

Sign up to request clarification or add additional context in comments.

1 Comment

oops! I didn't know. Thank you!
2

What I use is the file_exists($name_of_submitted_file) function at the end to see whether or not the file has been successfully uploaded.

1 Comment

Why does no one ever check the error code on PHP uploads... The file can theoretically exist even if it's not a valid upload.

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.