Jump to content

Recommended Posts

Hello. I'm a new user to this forum and a web development student. During my studies I have often searched tech forums for answers, but this is the first time I've registered....because I am currently learning PHP....and I like it, so I really want to understand it. This is my current issue: (I have reseached this error extensively...and cannot solve it).

 

Here is the error:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in …\image_window.php on line 23

 

Line 23 =    echo "<img src="C:/xampp/uploads/{$_GET['image']}\" $image[3] border=\"2\" />";

 

This code is from a text book, other than the directory path referred to in line 23.

HERE IS THE CODE:

<!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"xml:lang="en"lang="en">
<head>
   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
   <title>View Image</title>
</head>
<body>
<?php # image_window.php
// Set a variable for problem reporting.
$okay = FALSE;
// Make sure an image name was passed to the script.
if (isset($_GET['image'])) {
   // Get the extension of the image name.
   $ext = substr ($_GET['image'], -4);
   // Test if it's a valid image extension.
   if ((strtolower($ext) == '.jpg') OR (strtolower($ext) == 'jpeg') OR (strtolower($ext) == '.gif')) {
      // Get the image information and display the image.
     if ($image = @getimagesize ('uploads/' . $_GET['image'])) {
        echo "<img src="C:/xampp/uploads/{$_GET['image']}\" $image[3] border=\"2\" />";        
$okay = TRUE; // No problems.
     }
   } // End of extension IF.
} // End of isset() IF.

// If something went wrong...
if (!$okay) {
   echo '<div align="center"><font color="red" size="+1">This script must receive a valid image name!</font></div>';
}
?>
<br />
<div align="center"><a href="javascript:self.close();">Close This Window</a></div>
</body>
</html>

Any insight would truly be appreciated. Thank you!

 

CC

Link to comment
https://forums.phpfreaks.com/topic/205543-php-parse-error-help/
Share on other sites

You will definitely get an error here:

Line 23

echo "<img src="C:/xampp/uploads/{$_GET['image']}\" $image[3] border=\"2\" />";

 

It is because you were using double quote in placing the src attribute on the image without the forward slash and it is the same with the quote you used with the echo. Do it this way:

 

echo "<img src=\"C:/xampp/uploads/{$_GET['image']}\" $image[3] border=\"2\" />";

 

or alternatively:

 

echo '<img src="C:/xampp/uploads/'.$_GET['image'].'" '.$image[3].' border="2" />';

 

I prefer using the second one though as it looks cleaner for me.

 

cheers,

 

bluejay

Thanks for your help bluejay. I tried both examples you gave (I worked on the escaping quite a bit when I was trying to debug on my own). However, when using the backslashes, I then get this error:

 

This script must receive a valid image name!

 

Maybe that's the error I should have been addressing in the first place???? Thanks again.

 

CC

Thanks again bluejay. I believe $_GET['image'] is defined in the companion document, images.php with this code:

// Set the window properties.
      var window_specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizable=yes, left=0, top=0, width=" + width + ", height=" + height;
      // Set the URL.
      var url = "image_window.php?image=" + image;

 

 

During my debugging efforts, I tried to address the same question, but I wasn't exactly sure if $_GET['image'] had to be defined in the image_window script or if PHP knows that it was defined in the images.php script (don't forget, I am still learning).  I have attached the full images.php.

 

 

CC

 

[attachment deleted by admin]

In SRC attribute of an IMG tag, it should be the path of the image you want to display. It may take relative path or full path. Note also that the image should be existing on the same server the file is existing. Otherwise, you should specify the full path of the image you want to show, given its not on the same server.

 

For some reasons I don't what you were trying to do, are you uploading some picture or just passing location of an image so that it will be read next time around?

 

bluejay,

Thanks bluejay. I moved the uploads directory to the web root and it worked just fine with this code:

 

echo "<img src=\"/uploads/{$_GET['image']}\" $image[3] border=\"2\" />";

 

I guess I got thrown off because the text I was working from said it was perfectly o.k. to keep upload folder in directory other than the web root (for security purposes). I am sure that there is a way to do that, but I have had no luck figuring it out. Thanks again for your help.

 

God Bless,

CC

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.