我正在尝试在数据库中调用我的照片。我在本地完美运行,但是当我将文件放入FTP时,出现此错误:
加载图像时出错。找不到一个或多个图像。
这是我从DB调用的代码:
<?php
function gella($sayi){
$tanim = array(
"1" => "cubeRandom",
"2" => "block",
"3" => "cubeStop",
"4" => "cubeStopRandom",
"5" => "directionTop",
"6" => "showBarsRandom",
"7" => "horizontal",
"8" => "showBars",
"9" => "tube",
"10" => "circles",
"11" => "glassCube"
);
return $tanim[$sayi];
}
$sor = mysql_query("select * from pl_ust_banner");
while($y = mysql_fetch_object($sor)){
$ie++;
echo '<li><a href="#Random"><img src="Panel/Sayfalar/UstBanner/'.$y->resim.'" class="'.gella($ie).'" /></a> </li>';
}
?>
</ul>
</div>
因为在本地可以找到图像src
Panel/Sayfalar/UstBanner/
尽管当它在服务器上时并非如此。您需要将映像添加到服务器并更改目录,使其转到服务器上的映像。
尝试在 src 属性值中使用完整的 URL 路径。 src="http://domain.com/path/to/images/Panel/Sayfalar/UstBanner/..."
而不是使用相对 URI。此外,请确保您已将图像上传到其各自的目录,并且它们具有644
权限位(可公开访问)。
您还可以在回显图像路径之前验证图像路径是否存在。
while($y = mysql_fetch_object($sor)){
if(false === is_file('/path/to/images/Panel/Sayfalar/UstBanner/' . $y->resim){
continue;
}
//put your echo or other function if the file exists here.
}