/    Sign up×
Community /Pin to ProfileBookmark

Trouble using file input type

I have a form in which I have the following input to retrieve an image file from a user in my PHP page:

[code=html]<label for=”compImage”>Computer Photo: </label> <input type=”file” name=”compImage” id=”compImage” />[/code]

After choosing a file to upload, when I get to the subsequent PHP file to read in the values from my form, I have the following:

[code=php]$img = $_FILES[“compImage”];
$imgName = basename($_FILES[“compImage”][“name”]);[/code]

However, I am receiving an error from these lines that say “Undefined index: compImage”. I don’t see anything wrong with what I have here. Can somebody please help me figure this out?

Chris

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJan 06.2015 — Can we see all of the form html tags
Copy linkTweet thisAlerts:
@NogDogJan 06.2015 — In particular, make sure the containing form tag has the requisite enctype value: http://php.net/manual/en/features.file-upload.post-method.php
Copy linkTweet thisAlerts:
@ginerjmJan 06.2015 — Exactly what I wanted to see...
Copy linkTweet thisAlerts:
@chrscoteauthorJan 07.2015 — In particular, make sure the containing form tag has the requisite enctype value: http://php.net/manual/en/features.file-upload.post-method.php[/QUOTE]

That may be my issue. I didn't realize I needed enctype. I'll try that and get back to you.


Chris
Copy linkTweet thisAlerts:
@ginerjmJan 07.2015 — Check the manual (as for everything). Search $_FILES and you'll see a good sample.
×

Success!

Help @chrscote 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.19,
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,
)...