/    Sign up×
Community /Pin to ProfileBookmark

uploading a file help!!!

hi there, im a total newbie to php and i need some help on uploading a file to my server. basically ive taken the tutorial from html goodies and i cant get it to work. i have not got a clue. i have the code below can anyone possibly help me out, for a start i cant seem to see the code for where the files will be uploaded to (eg; home/username/area1/file, something along those lines). but like i said im a newbie and its probably staring me in the face :rolleyes:

——————-form.html——————————————-
<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”>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”10000000″ />
</form>

</body>

</html>
————————————————————————

———————getfile.php—————————————–
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php

if ( move_uploaded_file ($_FILES[‘uploadFile’] [‘tmp_name’],
“../uploads/{$_
FILES[‘uploadFile’] [‘name’]}”) )
{ print ‘<p> The file has been successfully uploaded </p>’;
}
else
{
switch ($_FILES[‘uploadFile’] [‘error’])
{ case 1:
print ‘<p> The file is bigger than this PHP installation allows</p>’;
break;
case 2:
print ‘<p> The file is bigger than this form allows</p>’;
break;
case 3:
print ‘<p> Only part of the file was uploaded</p>’;
break;
case 4:
print ‘<p> No file was uploaded</p>’;
break;
}
}

?>
</body>
</html>


—————————————————————–

any help would be greatly apreciated

cheers
rik

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Apr 06.2005 — Replace this line:

"../uploads/{$_FILES['uploadFile'] ['name']}"

with

realpath("../uploads/").$_FILES["uploadfile"]["name"];

You also need write permissions on the "uploads" directory for this to work. The uploads would be 1 level up from where your current location is. So, if your web location is

http://www.mysite.com/users/benman/data

Then the uploads folder is at:

http://www.mysite.com/users/benman/uploads
Copy linkTweet thisAlerts:
@rik4000authorApr 07.2005 — hi there, cheers for the reply. i done what you said.

replaced:

"../uploads/{$_FILES['uploadFile'] ['name']}"

with:

http://www.myarea.com/~rik04/data("../uploads/").$_FILES["uploadfile"]["name"];

where myarea.com is where i put the real address obviously

and i came accross this error.

Parse error: parse error, unexpected ':' in /home/bf02/bf02riot/public_html/dissertation/getfile.php on line 10

i assumed the : was the one in front of http as this was line 10 so i deleted it, then more and more errors kept comming, any ideas?.

i really need this to work

cheers

rik
Copy linkTweet thisAlerts:
@crh3675Apr 07.2005 — You can't upload via HTTP. And you kind of just answered your question with that error message. Did you set up an upload directory? You need to set one up like

[B]/home/bf02/bf02riot/public_html/uploads[/B] and make sure the webserver has write permissions to it. Also, "realpath" is a PHP function, not a fill-in-the-blank. Your script is fine but you need to setup the upload a directory called "uploads" where you created the "getfile.php" file. Oonce you do that, use this script for getfile.php:

[code=php]
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php

if (move_uploaded_file($_FILES['uploadFile']['tmp_name'], "uploads/{$_FILES['uploadFile']['name']}")){
print '<p> The file has been successfully uploaded </p>';
}else{
switch ($_FILES['uploadFile'] ['error']){
case 1:
print '<p> The file is bigger than this PHP installation allows</p>';
break;

case 2:
print '<p> The file is bigger than this form allows</p>';
break;

case 3:
print '<p> Only part of the file was uploaded</p>';
break;

case 4:
print '<p> No file was uploaded</p>';
break;
}
}

?>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@rik4000authorApr 08.2005 — hi there crh3675, cheers for all your help so far.

done all what you said, i get no errors but when i click the uploads button i just get a blank screen and nothing has been uploaded. ive put in the uploads directory and changed properties to 777.

any ideas????

cheers

rik
×

Success!

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