/    Sign up×
Community /Pin to ProfileBookmark

PHP image upload script

I’m trying to make a simple file-uploading thing to upload logos for each account into our database and I’m new to file uploading. It’s not finding a file at all. Here’s what I’ve got:

[CODE]move_uploaded_file($_FILES[“builderLogo”][“tmp_name”],
“../gallery/builders/” . $_FILES[“builderLogo”][“name”]);

if ($_FILES[“builderLogo”][“error”] > 0) {
echo “<p>Error: ” . $_FILES[“builderLogo”][“error”] . “</p>”;
}
else{
echo “<p>Upload: ” . $_FILES[“builderLogo”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“builderLogo”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“builderLogo”][“size”] / 1024) . ” Kb<br />”;
echo “Stored in: ” . $_FILES[“builderLogo”][“tmp_name”] . “</p>”;
}[/CODE]

And later:

[CODE]Name: <input type=”text” name=”builderName”>
<br/>Logo: <input type=”file” name=”builderLogo”>
<br/>Desc: <input type=”text” name=”builderDesc”>[/CODE]

It will make a new account and add it to the database, but the image uploading isn’t working at all. Any help/advice would be greatly appreciated.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@GalwayJul 28.2011 — Have you looked into the possibility of permission issues?
Copy linkTweet thisAlerts:
@ryanlundJul 29.2011 — I agree with Galway about the permissions but theres a chance of another more simple problem. Do you check if $_FILES is set and contains your information before attempting to move the file? If you do not, and the file isn't even uploading to the temporary directory then it could simply be a problem with your html.

Forgetting...
[code=html]
enctype='multipart/form-data'
[/code]


out of the form tag is probably the easiest mistake to make in the form.
×

Success!

Help @amandaNHT 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.27,
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,
)...