Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Upload Form - PLEASE HELP - It doesn't work!?
Old 12-09-2005, 07:50 PM PHP Upload Form - PLEASE HELP - It doesn't work!?
EGS
EGS's Avatar
Banned

Posts: 862
Name: Justice McCay
Location: New Jersey
Trades: 2
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!
Code:
<?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
EGS is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-10-2005, 03:25 AM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
You could try this:

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

if (!
is_uploaded_file($_FILES['file']['tmp_name'])) {
echo 
'<form method="post" action="upload.php" enctype="multipart/form-data"><input type="file" name="file"> <input type="submit" value="Upload!"></form>';
}
else{
$copy move_uploaded_file($_FILES["file"]["tmp_name"], $path."/".$_FILES["file"]["name"]);

if (
$copy == TRUE) {
echo 
"<a href='".$url."/".$_FILES["file"]["name"]."'>View your file!</a>";
} else {
echo 
"Nope didnt go through; go back and try again!";
}
}
?>
You shouldn't be using $_POST['file']

Edit: corrected the code
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Orodreth; 12-11-2005 at 07:41 AM..
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Old 12-10-2005, 10:55 AM
EGS
EGS's Avatar
Banned

Posts: 862
Name: Justice McCay
Location: New Jersey
Trades: 2
Ok does this file need to be CHMOD'ed or the directory or no?
I'm going to try this code. ^_^
EGS is offline
Reply With Quote
View Public Profile
 
Old 12-10-2005, 11:01 AM
EGS
EGS's Avatar
Banned

Posts: 862
Name: Justice McCay
Location: New Jersey
Trades: 2
I tried this and it gives this error:
Quote:
Originally Posted by PHP Error
Parse error: parse error, unexpected '{' in upload.php on line 23
EGS is offline
Reply With Quote
View Public Profile
 
Old 12-10-2005, 05:19 PM
Super Talker

Posts: 117
Trades: 0
if (!is_uploaded_file($_FILES['file']['tmp_name']) {

should change to :

if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
execute is offline
Reply With Quote
View Public Profile Visit execute's homepage!
 
Old 12-10-2005, 07:29 PM
Skilled Talker

Posts: 68
Trades: 0
i use this for my website and i no it works
HTML Code:
<html>
<h3>File Upload</h3> 
Select a file to upload:<br>
<form action="uploader.php" method="post" 
enctype="multipart/form-data">
<input type="file" name="file" size="45">
<br>
<input type="submit" value="Upload File">
</form>
and the php...

PHP Code:
<?php 

       
If ( $_FILES['file'] ['name'] != "" 
       { 
       
copy $_FILES['file'] ['tmp_name'], 
       
"/uploads" $_FILES['file']['name'] ) 
   or die ( 
"Could not copy file" ); 
       } 
       else{ die( 
"No file specified" ) ; } 
?> 

<h3> Upload Complete, File Upload Succeeded... </h3> 
<ui> 
<li> Sent: <?php echo $_FILES['file'] ['name'] ; ?> 
<li> Size: <?php echo $_FILES['file'] ['size'] ; ?> bytes 
<li> Type:<?php echo $_FILES['file'] ['type'] ; ?> 
</ul> 

<a href="/uploads/<?php echo $_FILES['file'] ['name'] ; ?>"> 
Click here to view the file</a>
mrpaul is offline
Reply With Quote
View Public Profile
 
Old 12-10-2005, 07:57 PM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
PHP Code:
"/uploads" $_FILES['file']['name'] ) 
should be
PHP Code:
"/uploads/" $_FILES['file']['name'] ) 
I'd also use move_uploaded_file instead of copy, but I guess it works too.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Old 12-10-2005, 10:13 PM
EGS
EGS's Avatar
Banned

Posts: 862
Name: Justice McCay
Location: New Jersey
Trades: 2
Thanks, Orodreth. I decided to use yours - success! It works!
Thanks so much dude!

Thanks everyone for your help! Have a great holiday!
EGS is offline
Reply With Quote
View Public Profile
 
Old 12-11-2005, 07:16 AM
Skilled Talker

Posts: 68
Trades: 0
sorry aobut that ye add the / if u use mine

Last edited by mrpaul; 12-11-2005 at 07:31 AM..
mrpaul is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Upload Form - PLEASE HELP - It doesn't work!?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30479 seconds with 12 queries