我想知道为什么即使从 MYSQL 正确检索图像路径后这些图像仍未显示我已经完成代码但我仍然无法弄清楚这是为什么:
<?php
$sql = "SELECT description, quantity, product_price, category, product_img_url";
$sql .= " FROM *****, *****";
$sql .= " WHERE product_id = product_img_id";
$sql .= " AND product_id = ?";
$sql .= " LIMIT 1";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('s', $id);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows==1){
$stmt->bind_result($desc,$qty,$pr,$cat,$product_img_url);
$stmt->fetch();
?>
<div id="infobox">
<h3>Product View</h3>
<p align="left">
<?php
if(file_exists($product_img_url)){
echo '<img src="'.$product_img_url.'" alt="" width="300" height="300" />';
}else{
echo '<img src="" alt="product image" />';
}
?>
有人能告诉我为什么会这样吗?
最佳答案
如果图像文件确实存在,那么这可能与路径有关。
我会使用 firebug 来处理图像 src 路径并尝试各种操作,例如在开头放置斜杠、删除斜杠或输入图像的绝对路径。
一旦我让图像显示在 firebug 中,我就会继续修复代码中的问题。
关于php - 图片路径不显示图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22749010/