PHP Upload Form - PLEASE HELP - It doesn't work!?
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!
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
Busy posted this at 07:00 — 10th December 2005.
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.
EGS posted this at 15:54 — 10th December 2005.
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.
Busy posted this at 21:00 — 10th December 2005.
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
EGS posted this at 03:15 — 11th December 2005.
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.