PHP getimagesize with variable

[亡魂溺海] 提交于 2019-12-13 20:42:06

问题


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:


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



来源:https://stackoverflow.com/questions/4742097/php-getimagesize-with-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!