/    Sign up×
Community /Pin to ProfileBookmark

Hello, I am 14 years old, and I need help with something. Just for the record, don’t think I am a retard, I know AS2.0 and 1.0, Javascript, HTML, and some PHP(just learning). But anyway, I am trying to make it so that people can upload files off their computer into my website, but….I have tried so many tutorials, and done so many tests, and I can’t get this to work quite the way I want it to. Can anyone slowly walk me through the process of making this on my site, oh and my site serves PHP, otherwise I would be learning ASP.

to post a comment
PHP

18 Comments(s)

Copy linkTweet thisAlerts:
@SheldonAug 26.2005 — post some code you have tried with

your html form and php upload script

[url=http://www.php.net]php.net[/url] is a great resource for learning


Sheldon
Copy linkTweet thisAlerts:
@cobrasniper555authorAug 26.2005 — ive tried the codes from www.htmlgoodies.com and the codes the the php manual that was in one of the posts earlier, thanks, ill try out the site though

-Brent
Copy linkTweet thisAlerts:
@cobrasniper555authorAug 26.2005 — ya, <a href="http://www.php.net">php.net</a> is the site I went to for some code, that and <a href="http://www.htmlgoodies.com">htmlgoodies.com</a>, but thanks anyway.
Copy linkTweet thisAlerts:
@SheldonAug 26.2005 — yes i understand you have tried, but post some code that you have tried with so that we can help you, lets see what you have got to find out your problems.


Sheldon

remember to use your [ php ] [/ php ] tags with your code.
Copy linkTweet thisAlerts:
@cobrasniper555authorAug 26.2005 — These are just the basics of the file upload forms, that I got. This one is from htmlgoodies.com and the one that I used for my site.

The html code for the upload form page:
[CODE]<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>

<form action="getfile.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="submit" value="Upload File">
</form>

</body>
</html>
[/CODE]

then this for the php page with the files:
[CODE]
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php

move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}")

?>
</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@SheldonAug 26.2005 — [code=php]
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>

<form action="getfile.php" method="post" enctype="multipart/form-data">
<br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="hidden" name="MAX_FILE_SIZE" value="1000" >//set max file size
<input type="submit" value="Upload File">
</form>

</body>
</html>
[/code]



getfile.php
[code=php]
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php
if(!empty($_FILES["uploadFile"])) {
$filename = $_FILES["uploadFile"]["name"];
$uploaddir = '/uploads/';//FileUploadPath
if (move_uploaded_file($_FILES["YourFile"]["tmp_name"], $uploaddir.$filename)){
echo 'File uploaded.';
} else {
echo 'Error!';
}
}
echo "<br>";
?>
</body>
</html>


[/code]


this code might not work but gives you an idea

what is the error you get when you try your script.

Sheldon
Copy linkTweet thisAlerts:
@cobrasniper555authorAug 26.2005 — uhhh....i don't know the error, because i erase my pages, but ill put them back up, hold on..
Copy linkTweet thisAlerts:
@cobrasniper555authorAug 26.2005 — Ok, it works now, but when I upload a file, a test file, it will say 'Error!'
Copy linkTweet thisAlerts:
@SheldonAug 26.2005 — whats your url and exact code?
Copy linkTweet thisAlerts:
@artoAug 26.2005 — cobrasniper555:

You didn't set [I]enctype[/I] in your form: [CODE]<form action="getfile.php" method="post" [B]enctype="multipart/form-data"[/B]><br>[/CODE]You should always set it to [I]multipart/form-data[/I] when uploading files.

sheldon:

You're trying to move wrong file: [CODE]if (move_uploaded_file($_FILES["[B]upload[/B]File"]["tmp_name"], $uploaddir.$filename)){ [/CODE]And upload path should probably be [I]../uploads/[/I].

Arto
Copy linkTweet thisAlerts:
@cobrasniper555authorAug 26.2005 — ya, there we go, thanks, it works now
Copy linkTweet thisAlerts:
@SheldonAug 26.2005 — cobrasniper555:

You didn't set [I]enctype[/I] in your form: [CODE]<form action="getfile.php" method="post" [B]enctype="multipart/form-data"[/B]><br>[/CODE]You should always set it to [I]multipart/form-data[/I] when uploading files.
[/QUOTE]

I did tell him to set that.



sheldon:

You're trying to move wrong file: [CODE]if (move_uploaded_file($_FILES["[B]upload[/B]File"]["tmp_name"], $uploaddir.$filename)){ [/CODE]And upload path should probably be [I]../uploads/[/I].

Arto[/QUOTE]


Yes i see, i had just quickly copied another script and missed one varible to change, sorry for putting you wrong cobrasniper555
Copy linkTweet thisAlerts:
@cobrasniper555authorAug 28.2005 — Ok, now I keep getting "error" everytime I try uploading a file, and the file is 11 KB, so it didn't pass the size limit. Can someone help me?
Copy linkTweet thisAlerts:
@bokehAug 28.2005 — Post the code you are using now. And post it between [code=php][/code]tags.
Copy linkTweet thisAlerts:
@bokehAug 28.2005 — Post the code you are using now. And post it between &#91;PHP]&#91;/PHP]tags.
Copy linkTweet thisAlerts:
@cobrasniper555authorAug 28.2005 — i put in the same codes that Sheldon gave me.
Copy linkTweet thisAlerts:
@SheldonAug 28.2005 — well did you make the changes that [b]Arto[/b] told you too? As arto said i had named the wrong file to upload so that wouldnt work.


Try this code i know it works now. Make sure there is a folder called "uploads" in the same dir as your getfile.php page. What file type are you trying to upload?

[code=php]<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>

<form action="getfile.php" method="post" enctype="multipart/form-data">
<br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="hidden" name="MAX_FILE_SIZE" value="10000" >//set max file size
<input type="submit" value="Upload File">
</form>

</body>
</html>
[/code]


getfile.php
[code=php]

<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php
if(!empty($_FILES["uploadFile"])) {
$filename = $_FILES["uploadFile"]["name"];
$uploaddir = '../uploads/'; //FileUploadPath
if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $uploaddir.$filename)){
echo 'File uploaded.';
} else {
echo 'Error!';
}
}
echo "<br>";
?>
</body>
</html>

[/code]
Copy linkTweet thisAlerts:
@Wisest_GuyAug 30.2005 — Im 15 and learning php. I tried to do the same thing yesterday and the problem was that permission was denied to save file. To allow access to save (i think) you need to edit the file php.ini on your server. I cannot access this file, so does anyone know how i could bypass this or something.
×

Success!

Help @cobrasniper555 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...