...

View Full Version : What does this mean?



jonw118
06-21-2005, 09:46 PM
Hello,

I am very much a newbie at PHP and trying waddle my way through here to get this one script working I need.

But it keeps telling me:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /client/home/matt.../docs/html/untitled1.php on line 89

Line 89 is: <a href=$_SERVER['PHP_SELF']?action=upload>Upload File</a>

Any help would so gratefully appreciated!!!

The full script I am trying to us is:
<?

$conn =mysql_connect('localhost', 'username', 'password'); //change to suit your database
mysql_select_db('filesdb', $conn);


$extlimit = "no"; //Do you want to limit the extensions of files uploaded
$limitedext = array(".gif",".jpg",".png",".jpeg"); //Extensions you want files uploaded limited to.
$sizelimit = "no"; //Do you want a size limit, yes or no?
$sizebytes = "200000"; //size limit in bytes
$dl = "http://www.ulnotes.com/testbank"; //url where files are uploaded
$absolute_path = "...\www\\testbank"; //Absolute path to where files are uploaded
$websiteurl = "http://www.test.com"; //Url to you website
$websitename = "k";

if (!isset($action)) {
$action = "";
}

switch($action) {
default:
echo"
<html>
<head>
<title>Upload Or Download</title>
</head>
<body>
<a href=$_SERVER['PHP_SELF']?action=upload>Upload File</a>
<a href=$_SERVER['PHP_SELF']?action=download>Download File</a>
<a href=$websiteurl>Return to $websitename</a>
<br><br>
</body>
</html>";
break;
case "download":

$result =mysql_query('SELECT `name`,`src` FROM `files` ORDER BY `id`', $con) or die(mysql_error());
echo "
<html>
<head>
<title>File Download</title>
</head>
<body><a href=$_SERVER['PHP_SELF']?action=upload>Upload File</a> <a href=$websiteurl>Return to $websitename</a>";
$list = "<table width=700 border=1 bordercolor=#000000 style=\"border-collapse: collapse\">";
$list .= "<tr><td width=700><center><b>Click To Download</b></center></td></tr>";
while($row = mysql_fetch_assoc($result)) {
$list .= "<tr><td width=700><a href=\'$row['src']\'>$row['name']</a></center></td></tr>";
}
$list .= "</table>";
echo $list;
echo"
<br><br>
</body>
</html>";

break;

case "upload":
echo"
<html>

<head>
<title>File Upload</title>
</head>

<body>

<form method=POST action=$_SERVER['PHP_SELF']?action=doupload enctype=multipart/form-data>
<p>File to upload:<br>
<input type=file name=file size=30><br>
<p>File to upload:<br>
<input type=text name=name>
<p><button name=submit type=submit>
Upload
</button>
</form>
<br><br>
</body>

</html>";
break;


//File Upload
case "doupload":
$dir = "dir";
if ($_FILES['file']['tmpname'] != "" && $_POST['name'] != "") {

if (file_exists("$absolute_path/$_FILES['file']['name']")) {
die("File already exists");
}

if (($sizelimit == "yes") && ($_FILES['file']['size'] > $sizebytes)) {
die("File is to big. It must be $sizebytes bytes or less.");
}

$ext = strrchr($_FILES['file']['name'],'.');
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
die("The file you are uploading doesn't have the correct extension.");
}

@copy($_FILES['file'], "$absolute_path/$_FILES['file']['name']") or die("The file you are trying to upload couldn't be copied to the server");

$sql = "INSERT INTO `files` (`id`,`name`,`src`) VALUES ('','$_POST['name']','$absolute_path/$_FILES['file']['name']');";
mysql_query($sql) or die("Could not add file to database");

} else {
die("Must select file to upload");
}
echo "
<html>
<head>
<title>File Uploaded</title>
</head>
<body>";
echo $file_name." was uploaded";
echo "<br>
<a href=$_SERVER['PHP_SELF']?action=upload>Upload Another File</a>
<a href=$_SERVER['PHP_SELF']?action=download> Download File</a>
<a href=$websiteurl> Return to $websitename</a><br><br>
</body>
</html>";
break;

}
mysql_close($con);
?>


And the my SQL is:
CREATE DATABASE `filesdb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE filesdb;

CREATE TABLE `files` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
`src` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

schleppel
06-21-2005, 10:21 PM
when putting arrays (eg. $_FILES['file']['name'] or $_SERVER['PHP_SELF']) in double quotes ", you should put curly braces around them.


if (file_exists("$absolute_path/$_FILES['file']['name']")) {
// becomes
if (file_exists("$absolute_path/{$_FILES['file']['name']}")) {
// or you could do this:
if (file_exists($absolute_path . '/' . $_FILES['file']['name'])) {

jonw118
06-24-2005, 06:56 PM
I made those changes, and unfortunately- still not working...

It references line 28 produces the error:
<a href=$_SERVER['PHP_SELF']?action=upload>Upload File</a>

Is there anything wrong in that particular line?

Thanks so much for anyone's help!

Jon

schleppel
06-24-2005, 07:13 PM
Like i said, when putting $_SERVER['PHP_SELF'] in double quotes you need curly braces around it.



<a href=$_SERVER['PHP_SELF']?action=upload>Upload File</a>
// becomes
<a href={$_SERVER['PHP_SELF']}?action=upload>Upload File</a>


From now on, whenever you get an error in this script, check it doesn't just need curly braces around an array in double quotes.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum