PHP Upload Form - PLEASE HELP - It doesn't work!?

They have: 161 posts

Joined: Jan 2005

So I tried to code a PHP upload form to upload some images into a folder on my site, but for SOME flippin' reason, it doesn't work! Mad

Please, somebody...tell me what I'm doing wrong!

<?php
$path
= "/home/bgamer/public_html/media";
$url = "http://www.boldgamers.com/media";

if (!
$_POST['file']) {
echo
'<form method="post" action="upload.php" enctype="multipart/form-data"><input type="file" name="file"> <input type="submit" value="Upload!"></form>';
}

if (
$_POST['file']) {
$copy = copy ($_FILES["file"]["tmp_name"], $path."/".$_FILES["file"]["name"]);

if (
$copy == TRUE) {
echo
"<a href='".$url."/".$_POST["file"]."'>View your file!</a>";
} else {
echo
"Nope didnt go through; go back and try again!";
}
}
?>
'
Note: That IS upload.php also Wink

Busy's picture

He has: 6,151 posts

Joined: May 2001

What errors do you get?

can try
if(move_uploaded_file($_FILES['file']['tmp_name'], $path."/".$_FILES['file']['name']))
{
view your file
}else{
no go
}
Also using function names is not a good idea.

They have: 161 posts

Joined: Jan 2005

What should I replace in my code with your code? The error I get is just that it doesn't work. Sad

Busy's picture

He has: 6,151 posts

Joined: May 2001

replace if ($_POST['file']) {
$copy = copy ($_FILES["file"]["tmp_name"], $path."/".$_FILES["file"]["name"]);

if ($copy == TRUE) {
echo "View your file!";
} else {
echo "Nope didnt go through; go back and try again!";
}
}

note you will have to add the bits I didn't put in, such as the image being displayed and a more user friendly error message

They have: 161 posts

Joined: Jan 2005

Success! I got it!
Thanks all. ^_^

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.