1

I have a form through which users can upload an image. On my home machine I was validating like so:

if(isset($_FILES['image']['name']))

And it was working fine, but it fails on my work machine. I need to use:

$_FILES['image']['name'] != ''

I've tried empty($_FILES['image']), but this doesn't work either. I was just wondering why this would be the case?

1
  • That shouldn't fail. Can you show the full code? Commented Feb 13, 2011 at 22:21

2 Answers 2

6

Even when $_FILES['photo'] is set, you should check $_FILES['photo']['error'] for exceptions such as partial uploads (UPLOAD_ERR_PARTIAL) or empty uploads (UPLOAD_ERR_NO_FILE) as explained in the Handling file uploads section of the PHP Manual.

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

Comments

0

The ['name'] might be unset or empty because POST forms are sent as multipart/form-data request type. And the filename= attribute is allowed to be empty. I'm not sure, but browsers might very well be configured (did you test with MSIE at work perchance?) to suppress it for security reasons. It's not an reliable field anyway.

This is no explanation why the $_FILES["image"] however was empty. I'd also surmise an upload error there. But anyway, you should be testing with print_r($_FILES);.
Also check the manual section on common pitfalls http://php.net/manual/en/features.file-upload.common-pitfalls.php regarding configuration settings.

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.