【发布时间】:2014-12-11 14:44:14
【问题描述】:
我在一个页面上编写了一个 PHP,该页面显示了从 XML 提要到另一个网站的信息。在提要中,我有一张我们想要显示的产品图片,但我需要添加外部网站地址作为前缀才能使其正常工作。
我在提要上的代码是:
$xml = simplexml_load_file('feed/myfeed.xml');
foreach ($xml->item as $item) {
$short_description = substr($item->descshort, 0, 200); ?>
<div class="row">
<div class="lhs col-md-9">
<h3><a href="register.php"><?php echo $item->name ?></a></h3>
<p class="pri">£<?php echo $item->regprice ?></p>
<p id="shown">
<?php echo $short_description; ?> ... <a href="<?php echo $item->link ?>">Read more</a></p>
</div>
<div class="rhs col-md-3"> //The following is the bit that I am struggling on
<img src="<?php echo 'http://mywebsite.com/myimagefolder/mysubimagefolder/' . $item->imgsm; ?>" alt="<?php echo $item->name ?>" height="150" />
</div>
</div>
但这给我的只是一条警告消息,我刚刚尝试访问http://mywebsite.com/myimagefolder/mysubimagefolder/
那么基本上我怎么能在开头添加http://mywebsite.com/myimagefolder/mysubimagefolder/ 并在其后添加文件名?
它可能很简单,但对我来说不是。请问有人可以帮我吗?
非常感谢。
【问题讨论】:
-
发出警告信息的具体内容是什么?
-
你确定
$item->imgsml不为空吗? -
外部服务器上的系统。它不喜欢你只是指文件夹。但是使用完整路径(网址和文件名),它可以毫无问题地显示图像。
-
@jurgemaister 这是一个错字,item->imgsm 无论如何都不是空的,即使在更正之后也是如此
-
图像是否被替换为带有错误消息的图像?如果是,那么您无能为力。
标签: php image url csv filepath