| | |
Parse Error in PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hi Everybody!
I'm trying to run the following script but I get this error:
Parse error: parse error, unexpected $ in c:\phpdev5\www\public\in.php on line 51
Any help would be appreciated.
Here are the files:
in.php (where the error is coming form):
[PHP]<html>
<head>
<title>CinnaHost Login</title>
</head>
<body bgcolor="#3366FF">
<center><h1><font color="#FFFFFF">Uploading...</font></h1>
<h2><font color="#FFFFFF">To Upload More Files, Click <a href="login.php"><font color="#FFFFFF">Here</font></a>.</font></h2>
</h1></center>
<?php
$filename = "../public/$_POST[site]/pswrd.pswrd";
$fp = fopen($filename,"r") or die ("Login Not Working - please try again.");
$pswrd = fgets($fp);
$attempt = "$_POST[password]";
$display_block = "";
if($pswrd == $attempt) {
echo "Login Successful!";
if("$_POST[uploadfile]" != "") {
//UPLOADING
$file_dir = "$_POST[uploadfile]";
foreach($_FILES as $file_name => $file_array) {
$display_block .= "File Path: ".$file_array['tmp_name']."<br>\n";
$display_block .= "Name: ".$file_array['name']."<br>\n";
$display_block .= "Type: ".$file_array['type']."<br>\n";
$display_block .= "Size: ".$file_array['size']."<br>\n";
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'],
"$file_dir/#file_array['name']") or die("Upload Failed. Possible reasons: file already exists.");
$display_block .= "<br><h3>FILE SUCCESSFULLY UPLOADED!</h3>";
echo $display_block;
}
}
}
if("$_POST[filetodelete]" != "") {
//DELETING
}
}
else {
echo "Login Failed - please try agin.";
}
?>
</body>
</html>[/PHP]
login.php (where the forms are):
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CinnaHost Login</title>
</head>
<body bgcolor="#3366FF">
<img src="logo.png" width="939" height="61" />
<br />
<table width="940" height="215" border="1">
<tr>
<td width="103" height="209"><center>
<h3>CinnaHost<br />
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
<param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button1.swf" />
<param name="quality" value="high" />
<embed src="button1.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
<param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button4.swf" />
<param name="quality" value="high" />
<embed src="button4.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
<param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button2.swf" />
<param name="quality" value="high" />
<embed src="button2.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
<param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button3.swf" />
<param name="quality" value="high" />
<embed src="button3.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
<param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button5.swf" />
<param name="quality" value="high" />
<embed src="button5.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
</h3>
</center></td>
<td width="821" bgcolor="#0000FF"><center>
<h2>CinnaHost Login/Upload:</h2>
</center>
<form action="in.php" method="post" enctype="multipart/form-data">
<p><strong> <font color="#FFFFFF">Site Name:</font><br />
<input name="site" type="text" />
<br />
<br />
<font color="#FFFFFF">Password:</font><br />
<input type="password" name="password" />
</strong><strong></strong>
<strong> <br />
<br />
<font color="#FFFFFF">File To Upload: If Not Uploading, Leave Blank.</font>
<br />
<input type="hidden" name="MAX_FILE_SIZE" value="51200" />
<input type="file" name="fileupload" />
<br />
<br />
<font color="#FFFFFF">If Deleting A File, Enter The Exact File Name (and extension). If Not Deleting, Leave Blank.</font><br />
<input type="text" name="filetodelete" />
<br />
<br />
<input type="submit" value="Login and Upload" />
</strong></p>
</form></td>
</tr>
</table>
</body>
</html>
[/PHP]
I'm trying to run the following script but I get this error:
Parse error: parse error, unexpected $ in c:\phpdev5\www\public\in.php on line 51
Any help would be appreciated.
Here are the files:
in.php (where the error is coming form):
[PHP]<html>
<head>
<title>CinnaHost Login</title>
</head>
<body bgcolor="#3366FF">
<center><h1><font color="#FFFFFF">Uploading...</font></h1>
<h2><font color="#FFFFFF">To Upload More Files, Click <a href="login.php"><font color="#FFFFFF">Here</font></a>.</font></h2>
</h1></center>
<?php
$filename = "../public/$_POST[site]/pswrd.pswrd";
$fp = fopen($filename,"r") or die ("Login Not Working - please try again.");
$pswrd = fgets($fp);
$attempt = "$_POST[password]";
$display_block = "";
if($pswrd == $attempt) {
echo "Login Successful!";
if("$_POST[uploadfile]" != "") {
//UPLOADING
$file_dir = "$_POST[uploadfile]";
foreach($_FILES as $file_name => $file_array) {
$display_block .= "File Path: ".$file_array['tmp_name']."<br>\n";
$display_block .= "Name: ".$file_array['name']."<br>\n";
$display_block .= "Type: ".$file_array['type']."<br>\n";
$display_block .= "Size: ".$file_array['size']."<br>\n";
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'],
"$file_dir/#file_array['name']") or die("Upload Failed. Possible reasons: file already exists.");
$display_block .= "<br><h3>FILE SUCCESSFULLY UPLOADED!</h3>";
echo $display_block;
}
}
}
if("$_POST[filetodelete]" != "") {
//DELETING
}
}
else {
echo "Login Failed - please try agin.";
}
?>
</body>
</html>[/PHP]
login.php (where the forms are):
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CinnaHost Login</title>
</head>
<body bgcolor="#3366FF">
<img src="logo.png" width="939" height="61" />
<br />
<table width="940" height="215" border="1">
<tr>
<td width="103" height="209"><center>
<h3>CinnaHost<br />
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20"><param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button1.swf" />
<param name="quality" value="high" />
<embed src="button1.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20"><param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button4.swf" />
<param name="quality" value="high" />
<embed src="button4.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20"><param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button2.swf" />
<param name="quality" value="high" />
<embed src="button2.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20"><param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button3.swf" />
<param name="quality" value="high" />
<embed src="button3.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
<br />
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20"><param name="BGCOLOR" value="#3366FF" />
<param name="movie" value="button5.swf" />
<param name="quality" value="high" />
<embed src="button5.swf" width="100" height="20" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#3366FF" ></embed>
</object>
</h3>
</center></td>
<td width="821" bgcolor="#0000FF"><center>
<h2>CinnaHost Login/Upload:</h2>
</center>
<form action="in.php" method="post" enctype="multipart/form-data">
<p><strong> <font color="#FFFFFF">Site Name:</font><br />
<input name="site" type="text" />
<br />
<br />
<font color="#FFFFFF">Password:</font><br />
<input type="password" name="password" />
</strong><strong></strong>
<strong> <br />
<br />
<font color="#FFFFFF">File To Upload: If Not Uploading, Leave Blank.</font>
<br />
<input type="hidden" name="MAX_FILE_SIZE" value="51200" />
<input type="file" name="fileupload" />
<br />
<br />
<font color="#FFFFFF">If Deleting A File, Enter The Exact File Name (and extension). If Not Deleting, Leave Blank.</font><br />
<input type="text" name="filetodelete" />
<br />
<br />
<input type="submit" value="Login and Upload" />
</strong></p>
</form></td>
</tr>
</table>
</body>
</html>
[/PHP]
Last edited by Ghost; Sep 21st, 2005 at 2:29 am. Reason: forgot to insert login.php
Not sure why you are getting the $ end of file notation error, all your brackets seem to be in order (of course I didn't check that closely but they appear to be in order).
Is the name='uploadfile' (login.php) meant for "$POST[fileupload]" (in.php)?
Also, in case you get an 'Undefined Index' error with $POST['fileupload'] ("$POST[fileupload]" as you have it listed) you may want to change:
to
Is the name='uploadfile' (login.php) meant for "$POST[fileupload]" (in.php)?
Also, in case you get an 'Undefined Index' error with $POST['fileupload'] ("$POST[fileupload]" as you have it listed) you may want to change:
PHP Syntax (Toggle Plain Text)
if("$_POST[uploadfile]" != "") {
to
PHP Syntax (Toggle Plain Text)
if(isset($_POST['fileupload'])) {
I would also recommend changing to what you had looks like it should be ok but it's better to be safe with arrays.
No obvious errors though...
PHP Syntax (Toggle Plain Text)
$filename = "../public/$_POST[site]/pswrd.pswrd";
PHP Syntax (Toggle Plain Text)
$filename = "../public/{$_POST['site']}/pswrd.pswrd";
No obvious errors though...
Thanks SarahK! It worked!!! Now, I have one more problem - it says the file was uploaded, but where was it uploaded to? Here's my upload code:
[PHP]$file_dir = "$_POST[uploadfile]";
foreach($_FILES as $file_name => $file_array) {
$display_block .= "File Path: ".$file_array['tmp_name']."<br>\n";
$display_block .= "Name: ".$file_array['name']."<br>\n";
$display_block .= "Type: ".$file_array['type']."<br>\n";
$display_block .= "Size: ".$file_array['size']."<br>\n";
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'],
"$file_dir/#file_array['name']") or die("Upload Failed. Possible reasons: file already exists.");
$display_block .= "<br><h3>FILE SUCCESSFULLY UPLOADED!</h3>";
echo $display_block;
}
} [/PHP]
Also, I want to upload the file in $_POST[sitename]/uploaded_file.html. Is my code correct?
Once again, THANK YOU SO MUCH!!!
[PHP]$file_dir = "$_POST[uploadfile]";
foreach($_FILES as $file_name => $file_array) {
$display_block .= "File Path: ".$file_array['tmp_name']."<br>\n";
$display_block .= "Name: ".$file_array['name']."<br>\n";
$display_block .= "Type: ".$file_array['type']."<br>\n";
$display_block .= "Size: ".$file_array['size']."<br>\n";
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'],
"$file_dir/#file_array['name']") or die("Upload Failed. Possible reasons: file already exists.");
$display_block .= "<br><h3>FILE SUCCESSFULLY UPLOADED!</h3>";
echo $display_block;
}
} [/PHP]
Also, I want to upload the file in $_POST[sitename]/uploaded_file.html. Is my code correct?
Once again, THANK YOU SO MUCH!!!
![]() |
Similar Threads
- Parse error in code (PHP)
- Help. Parse error in PHP code (PHP)
- PHP Parse error: parse error, unexpected T_STRING in F:\downloads\cats-0.6.1\index.ph (PHP)
- PHP Parse error: parse error, unexpected T_STRING (PHP)
- Parse error: (PHP)
- I need help with a parse error! (PHP)
Other Threads in the PHP Forum
- Previous Thread: Making a Remote Host
- Next Thread: Cool Developer Tool!!
| Thread Tools | Search this Thread |
advanced alerts apache api archive array autosuggest beginner binary broken cakephp checkbox class clients cms code cron curl database date datepart display dynamic echo email emptydisplayvalue eregi error execute explodefunction file files folder form forms function functions google hack head href htaccess html if...loop image include insert ip javasciptvalidation javascript joomla keywords library limit link login mail matching menu mlm multiple mysql object oop password paypal pdf php phpincludeissue query radio random recursion recursive remote script search searchbox server sessions shot smarty source space speed sql syntax system table tutorial update upload url validator variable vbulletin video web website youtube





