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):

<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>

login.php (where the forms are):

<!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:D27CDB6E-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:D27CDB6E-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:D27CDB6E-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:D27CDB6E-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:D27CDB6E-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>

Recommended Answers

All 4 Replies

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 ("$POST[fileupload]" as you have it listed) you may want to change:

if("$_POST[uploadfile]" != "") {

to

if(isset($_POST['fileupload'])) {

I tried that, but I'm still getting that error. Any other suggestions? Also, should I used $_POST instead of $_POST[blank]? Thanks.

I would also recommend changing

$filename = "../public/$_POST[site]/pswrd.pswrd";

to

$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...

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:

$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;
            }
            
        }

Also, I want to upload the file in $_POST[sitename]/uploaded_file.html. Is my code correct?

Once again, THANK YOU SO MUCH!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.