/    Sign up×
Community /Pin to ProfileBookmark

Hey, when people are on my site, they want to upload files like avatars.
Does anybody know the code to make a form where you can fill in the file on your harddisk and when you submit the file is uploaded to my server?
thanks greetzzz tAK

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Apr 13.2004 — <i>
</i>
&lt;form method="post" encoding="multopart/form-data"&gt;
&lt;input type="file size="35" name="filetoupload"/&gt;
&lt;input type="submit" name="upload" value="Upload"/&gt;
&lt;/form&gt;


Of course, you need some server-side code to process the upload...
Copy linkTweet thisAlerts:
@The_Anime_KingauthorApr 13.2004 — Well that's what i mean ?

i'd like to have the complete code with the php needed to save the file on the server. sorry for not putting that in my question...

well do you have the php code too? that would be really great.

thanks so far

greetzzz tAK
Copy linkTweet thisAlerts:
@crh3675Apr 13.2004 — Thought you wouldn's ask

<i>
</i>&lt;?php


<i> </i>$UploadDir = './';
<i> </i>$UploadFileName = $UploadDir . $_FILES['filetoupload']['name'];

<i> </i>print "&lt;pre&gt;";

<i> </i>if (move_uploaded_file($_FILES['filetoupload']['tmp_name'], $UploadFileName)) {
<i> </i> print "File successfully uploaded. ";
<i> </i> print "Debug information:n";
<i> </i> print_r($_FILES);
<i> </i>} else {
<i> </i> print "File exceed the limited size!n";
<i> </i> print_r($_FILES);
<i> </i>}
<i> </i>print "&lt;/pre&gt;";
?&gt;



This will should work on newer versions of PHP
Copy linkTweet thisAlerts:
@The_Anime_KingauthorApr 13.2004 — Two more questions ?

How can i make a "browse"-button and why does the script not work:

http://members.lycos.nl/rpgcontestdb/uploader.php

Thanks for your time ?

greetzzz tAK
Copy linkTweet thisAlerts:
@crh3675Apr 13.2004 — First off, there was a closing quote missing in the form:

<i>
</i>&lt;form method="post" enctype="multipart/form-data" action="upload.php"&gt;
&lt;input type="file" size="35" name="filetoupload"/&gt;
&lt;input type="submit" name="upload" value="Upload"/&gt;
&lt;/form&gt;



Do you have permissions to write files to the server.

I also kinda fat-fingered some of the form code becuase I typing too fast, sorry
Copy linkTweet thisAlerts:
@The_Anime_KingauthorApr 13.2004 — well, the layout improved a lot but... it still doesn't work i'm afraid

you said it may be something with the writing permissions. Can you try the script and see if that really is the problem?

it's still the same url ?

greetzzz tAK
Copy linkTweet thisAlerts:
@crh3675Apr 13.2004 — Add this tag to your form and try again:

<i>
</i>&lt;input type="hidden" name="MAX_FILE_SIZE" value="50000" /&gt;
Copy linkTweet thisAlerts:
@The_Anime_KingauthorApr 13.2004 — I'm sorry, but it still doesn't work...?

it's not the filesize limit, because i changed that...

greetzz tak
Copy linkTweet thisAlerts:
@crh3675Apr 14.2004 — You probably do not have permission to create files as the "httpd" webuser. You will have to contact your hosting provider.
×

Success!

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