944,202 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2737
  • PHP RSS
Sep 21st, 2005
0

Parse Error in PHP

Expand Post »
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="clsid27CDB6E-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="clsid27CDB6E-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="clsid27CDB6E-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="clsid27CDB6E-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="clsid27CDB6E-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
Similar Threads
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Sep 21st, 2005
0

Re: Parse Error in 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:

PHP Syntax (Toggle Plain Text)
  1. if("$_POST[uploadfile]" != "") {

to

PHP Syntax (Toggle Plain Text)
  1. if(isset($_POST['fileupload'])) {
Reputation Points: 41
Solved Threads: 2
Junior Poster in Training
fsn812 is offline Offline
93 posts
since Jan 2004
Sep 22nd, 2005
0

Re: Parse Error in PHP

I tried that, but I'm still getting that error. Any other suggestions? Also, should I used $_POST['blank'] instead of $_POST[blank]? Thanks.
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
Sep 22nd, 2005
0

Re: Parse Error in PHP

I would also recommend changing
PHP Syntax (Toggle Plain Text)
  1. $filename = "../public/$_POST[site]/pswrd.pswrd";
to
PHP Syntax (Toggle Plain Text)
  1. $filename = "../public/{$_POST['site']}/pswrd.pswrd";
what you had looks like it should be ok but it's better to be safe with arrays.

No obvious errors though...
Reputation Points: 10
Solved Threads: 1
Junior Poster
sarahk is offline Offline
138 posts
since Apr 2005
Sep 22nd, 2005
0

Re: Parse Error in PHP

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!!!
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Making a Remote Host
Next Thread in PHP Forum Timeline: Cool Developer Tool!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC