【问题标题】:Retrieving images from the path data saved at SQL database从保存在 SQL 数据库的路径数据中检索图像
【发布时间】:2013-08-31 16:54:03
【问题描述】:

我从 SQL 数据库中检索商店图像和内容的部分代码(只有路径保存在数据库中)如下。我得到了显示的内容,除了图像。

我的数据库记录显示路径为; C:/xampp/htdocs/bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG

我输入的图像源似乎对我没有帮助。如何调整我的方法以确保从数据库中提取图片?

代码如下;

<?php
$j=0;
while ($rows = mysql_fetch_assoc($query))
{
?>
    <tr style="height:100px; font-family: Georgia, 'Times New Roman', Times, serif;">
    <td style=" width:100px;">        
    <img src='<?php $rows['pictures'];?>'><br><br>
    </td>
    <td style="text-align:justify;"><?php echo $rows['description'];?><br><br></td>
    <td style="text-align:right;"><?php echo $rows['brand'];?><br><br></td>
    <td style="text-align:right;"><?php echo $rows['model'];?><br><br></td>
    <td style="text-align:right;"><?php echo $rows['unitprice'];?><br><br></td>
    <td style="text-align:right;"><?php echo $rows['availability'];?> units available<br><br></td>
    <td><input type='submit' id='buynow[]' class='buynow' name='but' value='Buy'><br><br></td>
    </tr>
<?php
$j++;
}
echo "</table>";
}?>

【问题讨论】:

    标签: php


    【解决方案1】:

    您必须只插入不包括文档根目录的相对路径。也就是说,如果您的文档根目录设置为仅 htdocs 文件夹(在 apache 中默认为 localhost),那么您必须在您的情况下从该文档根目录插入图像路径

    /bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG

    是的,您也需要回显该变量。

    【讨论】:

      【解决方案2】:

      先试试html链接

      <img src='bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG' />
      

      好的

      试试这个固定的:&lt;img src='&lt;?php echo substr_replace($rows['pictures'], '',0, 16);?&gt;'/&gt;

      【讨论】:

      • 您的工作方式。但是存储在数据库中的路径如上。我该如何应对?
      • 如果您无法更改它在数据库中的存储方式或使用substr_replace(),则将由 start 和(可选)长度参数分隔的字符串副本替换为替换的字符串。
      • 在这种情况下substr() 会更简单:substr($path, 16)
      猜你喜欢
      • 1970-01-01
      • 2011-02-20
      • 2012-01-27
      • 1970-01-01
      • 2019-04-02
      • 2018-02-01
      • 1970-01-01
      • 2014-06-07
      • 2019-01-05
      相关资源
      最近更新 更多