【发布时间】:2015-07-20 21:01:16
【问题描述】:
编辑:
1 - $search_result['image'] 打印 URL,例如:http://www.desktopwallpaperhd.net/wallpapers/21/7/wallpaper-sunset-images-back-217159.jpg
2 - 尝试删除包含并将代码直接放在 screenshots.php 中,但我根本没有任何更改。
3 - 认为可能由于 foreach 循环我无法请求函数,所以我将其更改为 while($search_result, mysqli_fetch_array()) 并将 sql 咨询为 mysqli_query 但页面不会加载
我在 google 上搜索了两天,但无法让它工作,我的一个朋友告诉我这个网站,以及它是如何工作的,所以...... 重点:
我正在尝试检查图像 URL 是否存在,以及它是否将图像的 src 作为 url 本身返回,如果图像 URL 不再存在或从未存在,则图像 src 将更改为一个默认值。
问题是所有的 URL 都在数据库中... 这是我的php代码:
screenshots.php
<?php
echo '<div class="dv_alb_pics" id="alb_ev_pics">';
include('scripts/sug.php');
echo $evs_content.'</div>';
?>
sug.php
<?php
$images_search = $SQL->query("SELECT * FROM `screenshots` WHERE `section` = '1' AND `status` = '1' ORDER BY `date` DESC LIMIT 50;")->fetchAll();
$evs_content .= '<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>';
foreach($images_search as $search_result) {
if(file_exists($search_result['image'])) {
$img_source = $search_result['image'];
} else {
$img_source = 'images/none.png';
}
$evs_content .= '<div class="ss_picture_rightside"><img class="ss_p_img_rightside" src="'.$img_source.'"></div>';
}
$evs_content .= '</td>
</tr>
</table>';
?>
在搜索时,我在帖子中看到一个人说file_exists() 适用于 php 5+ 中的 URL
事实证明他可能错了,因为它根本不起作用
我也尝试了一些CURL 方法,但是当我在foreach() 中使用CURL 时,我的屏幕截图页面无法加载
如果有任何建议,我将不胜感激,谢谢!
【问题讨论】:
-
你必须使用
file_exists的绝对路径。 -
请指出 $img_source 中的内容
-
$search_result['image']中存储的内容是file.jpg还是path/to/file.jpg -
@donald123 已编辑,谢谢!
$search_result['image']打印一个 url -
从技术上讲,您可以通过简单的 JS
on error类型调用来避免所有这些废话......