Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validate file upload

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
I'm looking for a simple way to check to see if a file input field has a value. I have an upload field, however, if they choose to put something in that field, it will replace the existing item in the database. This is what I want, however, if they leave it blank, it erases the existing item in the database. How can I check to see if the file input field has a file in it?

I've tried:
Code:
if(empty($_FILES['attachment']['name']) || $_FILES['attachment']['name'] == ""){

Thanks!

_______________
_brian.
 
Check the $_FILES error variable, if the value is 4 then no file was uploaded.

Code:
<?php
if ($_FILES['attachment']['error'] == 4) {
    //no file uploaded
}
?>
File error code meanings can be found on the Error Messages Explained page in the PHP manual.
 
Excellent Thanks.

I also figured out I had a misspelled variable (attachement instead of attachment)...

_______________
_brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top