0

I'm trying to use the getimagesize function to get the height and with of an image. I'm pulling the image URL from a database. (The field ProjectURL contains a line such as xxx.jpg). However I'm getting an error.

Code:

$testing = "projects/'.$row['ProjectURL'].'";
    list($width, $height, $type, $attr) = getimagesize($testing);
    echo "Image width " .$width;
echo "<br />";
echo "Image height " .$height;

Error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

1
  • 3
    Your first ' should be a ". Use a decent IDE or editor with syntax highlighting, it will make finding such errors much easier Commented Jan 19, 2011 at 23:49

1 Answer 1

6

it's because you are mixing single and double quotes...

this should be ok:

$testing = "projects/" . $row['ProjectURL'];
list($width, $height, $type, $attr) = getimagesize($testing);
echo "Image width " . $width;
echo "Image height " . $height;

You might also have noticed that I removed the echo "";... this one was useless :)

Sign up to request clarification or add additional context in comments.

3 Comments

echo "<br />"; is not useless , otherwise it echoes them on the same line :) the better approach would be echo "Image width " . $width. "\n";
Last time I saw the article, there was no "<br />" but a \n... :)
Thanks very much Paul, it was the mixture of quotes. Working now, cheers :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.