/    Sign up×
Community /Pin to ProfileBookmark

move_uploaded_file

Trying to copy a file in PHP and get this error in ini_set…

Notice: Undefined index: upload in /Applications/MAMP/htdocs/lostpet3/postaction.php on line 36

Here’s my dump…..any ideas why if(move_uploaded_file($_FILES[‘uploadedfile’][‘tmp_name’], $target))

won’t work? My code is below…

POST:Array
(
[date1] => 04/21/2011
[optType] => Dog
[optStatus] => Lost
[txtName] => sdtsd
[txtDescription] => edfds
[txtContact] => dsfsd
[txtArea] => dsfdsfsd
)
FILES:Array
(
[Upload] => Array
(
[name] => IMG_6539.jpg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpkJ4Q00
[error] => 0
[size] => 4831277
)

)

Notice: Undefined index: upload in /Applications/MAMP/htdocs/lostpet3/postaction.php on line 36

Notice: Undefined index: uploadedfile in /Applications/MAMP/htdocs/lostpet3/postaction.php on line 39

Notice: Undefined index: uploadedfile in /Applications/MAMP/htdocs/lostpet3/postaction.php on line 41

Notice: Undefined index: uploadedfile in /Applications/MAMP/htdocs/lostpet3/postaction.php on line 46

Sorry, there was a problem uploading your file.

=================================
$target = “gallery/”;
$target = $target . basename( $_FILES[“uploadedfile”][“name”]);

if(move_uploaded_file($_FILES[‘uploadedfile’][‘tmp_name’], $target))
{
echo “The file “. basename( $_
FILES[‘uploadedfile’][‘name’]). ” has been uploaded”;
}
else {
echo “<BR>Sorry, there was a problem uploading your file.<BR>” . basename($_FILES[‘uploadedfile’][‘name’]);
}

exit();

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 21.2011 — First guess would be that you did not set the proper enctype value in your <form> tag. Second guess would be a typo somewhere such that the file-type field's name in the form is not matching the name you are using as the first index in the $_FILES array.
Copy linkTweet thisAlerts:
@eforceauthorApr 21.2011 — enctype is good. 1st thing I checked. I used Upload as the name of my File Type. Is the name in basename( $_FILES["uploadedfile"]["name"]) not a constant? No Typo anyway.
Copy linkTweet thisAlerts:
@NogDogApr 21.2011 — If you used "Upload" as the name of the field, e.g. [b]<input type='file' name='Upload' />[/b], then your $_FILES reference would be [b]$_FILES['Upload']['name'][/b]. Note that it will be case-sensitive, too (I think?).
Copy linkTweet thisAlerts:
@eforceauthorApr 21.2011 — ROFL......Thanks. That worked.
×

Success!

Help @eforce 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.29,
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,
)...