0

图像存在于我的服务器中,但我无法在以下代码的帮助下找到或显示图像

$myimages='/uk/images/7.jpg';
echo $myimages;
echo '<img src="'; echo $myimage; echo '">';

if (file_exists($myimages)) {
    echo "The file $myimages exists";
}
else {
    echo "The file $myimages does not exist";
    $myimages=$info['aw_image_url'];
    echo $myimages;
}

代码总是返回The file doesn't exist也不显示图像。代码有什么问题?

4

4 回答 4

2

The path is correct for your browser, but not for file_exists. It checks path relative to your filesystem, so if you start the path with /, it will check starting from the root of your filesystem

Also, variable name where you're outputing image is $myimages, not $myimage

于 2013-03-09T15:29:23.457 回答
0

1)您使用不同的变量来输出图像标签,因此图像标签被破坏

2)file_exists查看服务器的绝对路径,因此它不是从图像标签查看的“webroot”角度查看它

于 2013-03-09T15:31:37.310 回答
0

尝试这个

$myimages="uk/images/7.jpg";
 echo $myimages;
 echo "<img src='$myimages' />";



if (file_exists($myimages)) {
    echo "The file $myimages exists";
} else {
echo "The file $myimages does not exist";
$myimages=$info['aw_image_url'];
echo $myimages;
}
于 2013-03-09T15:32:42.117 回答
-3

You need to close the image tag with /

$myimages='/uk/images/7.jpg'; echo $myimages; echo '<img src="'; echo $myimages; echo '"/>';

Note you are also missing the letter "s" in the $myimages variable on line three

于 2013-03-09T15:28:55.853 回答