简体   繁体   English

PHP getimagesize与变量

[英]PHP getimagesize with variable

I'm trying to use the getimagesize function to get the height and with of an image. 我正在尝试使用getimagesize函数来获取图像的高度和图像。 I'm pulling the image URL from a database. 我正在从数据库中提取图像URL。 (The field ProjectURL contains a line such as xxx.jpg ). (字段ProjectURL包含一行,例如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 解析错误:语法错误,意外的T_ENCAPSED_AND_WHITESPACE,预期为T_STRING或T_VARIABLE或T_NUM_STRING

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 :) ...这没用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM