Jump to content

[SOLVED] file upload help...


ardyandkari

Recommended Posts

hi.  i am trying to get a file upload script to work, but it doesn't.

 

i am using php 4.1 i believe (godaddy) not 5.

 

what i am trying to do is upload a file and then put the file name into a database where i can simply echo the name like this

echo "<img src = "upload/$foo">" or whatever...i am probably wrong on the syntax or something but you get the point.

 

i have the following script:

 

<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
echo "<a href='fileupload.htm'>CLICK HERE to return.</a>";
}
else {
echo "Sorry, there was a problem uploading your file.";
echo "<a href='fileupload.htm'>CLICK HERE to return.</a>"

}
?>
<?php
$hostname="sqlserver";
$username="username";
$password="password";
$dbname="database";
$usertable="table";

mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);
$query="INSERT INTO `customers` (file) VALUES ('{$target}') ";
$result = mysql_query($query) or die(mysql_error());

?>

 

i get the following error:

 

Parse error: parse error, unexpected '}', expecting ',' or ';' in /home/content/r/y/a/ryancyschultz/html/fileupload.php on line 17

 

15:  echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

16:  echo "<a href='fileupload.htm'>CLICK HERE to return.</a>";

17:  }

 

i tried taking out the echo lines completely and nothing...any help is GREATLY appreciated.  thanks a lot.

 

also, i am making this script for a site, but it will be password protected, so dont worry about telling me how insecure this is i already know.

 

thanks again.

Link to comment
https://forums.phpfreaks.com/topic/73190-solved-file-upload-help/
Share on other sites

<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
echo "<a href='fileupload.htm'>CLICK HERE to return.</a>";
}
else {
echo "Sorry, there was a problem uploading your file.";
echo "<a href='fileupload.htm'>CLICK HERE to return.</a>"; // you're missing a semi-colon

}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.