Check file upload selected

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
agibsonsw
Forum Newbie
Posts: 8
Joined: Sun Apr 11, 2010 1:58 pm

Check file upload selected

Post by agibsonsw »

Hello.
Using a file input type how can I check whether any file was selected?
I've tried 'isset($_FILES['Resume'])' and '$_FILES['Resume']['size']>0' but no joy. Thanks, Andy.
agibsonsw
Forum Newbie
Posts: 8
Joined: Sun Apr 11, 2010 1:58 pm

Re: Check file upload selected

Post by agibsonsw »

I've discovered that

Code: Select all

if (empty($_FILES['Resume']['name'])) {
            echo "You haven't selected a file.<br />";
            exit();
}
seems to work, but I'm not sure why the other versions don't. Anyone know why? Thanks, Andy.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Check file upload selected

Post by requinix »

The correct method is to check $_FILES[...][error]: if it ==4 then no file was uploaded.
Post Reply