/    Sign up×
Community /Pin to ProfileBookmark

Check for $_FILES

I am trying to create a check in my code to see if an image was selected in my form

[code=php]if(isset($_FILES[‘image’]))[/code]

doesn’t seem to work, as in it keeps telling me is NOT set even when I select an image to upload. I’ve heard of using

[code=php]if($_FILES[‘image’][‘name’] != “”)[/code]

but don’t seem that working either…

Help please…thanks.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 03.2013 — Did you include [B][FONT=Courier New]enctype="multipart/form-data"[/FONT][/B] in your <form> tag?
Copy linkTweet thisAlerts:
@NogDogJul 03.2013 — How about either echoing or logging what's in $_FILES just to see if you're actually getting anything, and if so, how the array is indexed and such (remember that array keys are case-sensitive, just in case):

[code=php]
echo "<pre>".print_r($_FILES, 1)."</pre>n";

// or:

error_log('$_FILES:'.PHP_EOL.print_r($_FILES, 1));
[/code]
×

Success!

Help @Dragonfire2008 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...