如何找出所有产品中的缺失图片?
2012-06-20 09:44
381 查看
昨天突然发现公司受理的一个网站有些图片不显示。初步认为是图片地址失效或者本地图片库图片缺失,于是写了个检查的小程序,写下来,面得忘记了。
首先用sql语句查找所要检查的产品
因为图片存在于产品描述中,我们只对有产品描述的产品进行查找
产品描述中要有图片才可能出现不显示的情况,所以
正则表达式是我无耻的从网上拿来用的,鄙视一下。
之后输出一些关键信息查看
再用preg_match_all() 函数检查所以图片
foreach() 循环检查
输出没有的图片
如果是外连图片就直接输出
最后运行看输出的结果
唉,最后还得人工检查,真失败。如果能写成自动的就好了,目前没想到方法。
附:后来要求找出已经恢复的产品相的产品号
修改了下上面的程序,终于不用手工了
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require('includes/application_top.php'); $res = tep_db_query("select * from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int) $languages_id . "'"); while ($product_info = tep_db_fetch_array($res)) { if (!empty($product_info['products_description'])) { if (preg_match('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $product_info['products_description'])) { echo '<span style="color:red;">' . $product_info['products_model'] . '</span>'; echo '########## id:' . $product_info['products_id']; echo '----------------link:<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product_info['products_id']) . '">' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product_info['products_id']) . '</a>'; echo '<br>'; preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $product_info['products_description'], $outinfo); foreach ($outinfo[1] as $key => $out) { echo $out . '<br>'; $hostnameby = substr($out, 0, 23); $hostnamebywww = substr($out, 0, 27); if ($hostnamebywww === 'http://xxx.xom/') { $imgurl = substr($out, 27); }else if ($hostnameby === 'http://www.xxx.xom/') { $imgurl = substr($out, 23); }else{ echo 'this is old<br>'; echo '<img src="'.$out.'" width="200" height="200"/><br>'; } define('PC_PATH', dirname(__FILE__)); define('DS', DIRECTORY_SEPARATOR); if (!file_exists(PC_PATH . DS . $imgurl)) { echo '<img src="'.HTTP_SERVER . '/' . $imgurl . '" width="200" height="200"/><br>'; echo $imgurl.'<br>'; } unset($imgurl); } echo '<br><br>'; } } } require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
首先用sql语句查找所要检查的产品
因为图片存在于产品描述中,我们只对有产品描述的产品进行查找
if (!empty($product_info['products_description'])) {}
产品描述中要有图片才可能出现不显示的情况,所以
if (preg_match('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $product_info['products_description'])) {}
正则表达式是我无耻的从网上拿来用的,鄙视一下。
之后输出一些关键信息查看
再用preg_match_all() 函数检查所以图片
foreach() 循环检查
输出没有的图片
if (!file_exists(PC_PATH . DS . $imgurl)) { echo '<img src="'.HTTP_SERVER . '/' . $imgurl . '" width="200" height="200"/><br>'; echo $imgurl.'<br>'; }
如果是外连图片就直接输出
}else{ echo 'this is old<br>'; echo '<img src="'.$out.'" width="200" height="200"/><br>'; }
最后运行看输出的结果
唉,最后还得人工检查,真失败。如果能写成自动的就好了,目前没想到方法。
附:后来要求找出已经恢复的产品相的产品号
修改了下上面的程序,终于不用手工了
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ //找出已更新的 require('includes/application_top.php'); $res = tep_db_query("select * from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int) $languages_id . "'"); while ($product_info = tep_db_fetch_array($res)) { if (!empty($product_info['products_description'])) { if (preg_match('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $product_info['products_description'])) { echo '<span style="color:red;">' . $product_info['products_model'] . '</span>'; echo '########## id:' . $product_info['products_id']; echo '----------------link:<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product_info['products_id']) . '">' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product_info['products_id']) . '</a>'; echo '<br>'; $link = tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product_info['products_id']); preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $product_info['products_description'], $outinfo); //print_r($outinfo); foreach ($outinfo[1] as $key => $out) { echo $out . '<br>'; $hostnameby = substr($out, 0, 31); $hostnamebywww = substr($out, 0, 35); if ($hostnamebywww === 'http://www.xxx.xxx/picture/') { $imgurl = substr($out, 35); } else if ($hostnameby === 'http://xxx.xxx/picture/') { $imgurl = substr($out, 31); } else { $imgurl = ''; } if ($imgurl != '') { echo '<img src="' . HTTP_SERVER . '/picture/' . $imgurl . '" width="200" height="200"/><br>'; echo $imgurl . '<br>'; $content.=$product_info['products_model']; $content.="," . $link; $content.="," . HTTP_SERVER . '/picture/' . $imgurl; //$content.=","; $content = $content . "\r\n"; } unset($imgurl); } echo '<br><br>'; } } } $fp = fopen("imginfo.csv", 'w'); fwrite($fp, $content); fclose($fp); require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
相关文章推荐
- 如何提取图片的所有像素的颜色RGBa值?
- 设置批量商品优惠、如何修改ZenCart产品显示图片的大小
- Canvas如何等待所有图片加载完成才开始绘图
- 如何检索获取安卓图片数据库的所有信息
- 如何快速提取word中所有图片
- 进击的KFC:iOS WebView 如何通过js获取网页中所有图片并加入点击事件,实现浏览图片的功能
- ACCESS 如何获取所有菜单栏命令按钮的图片以及FaceID?
- 如何修改Magento前台显示的产品图片的尺寸大小
- magento -- 如何取得一个分类的所有产品
- 如何用正则表示式获得一个页面内容中所有图片地址
- 如果让你来制作一个访问量很高的大型网站,你会如何来管理所有CSS文件、JS与图片?
- 如何遍历文件夹下的所有图片(Pyhton&C++)
- Magento入门基础 - 后台如何批量导入产品及产品图片
- css 如何设置 某div 里面的所有图片的最大宽度。当加入文章里图片时,图片自动按比例减小。
- 如何实现 asp 上传产品图片加水印功能
- 如何在一个范围内找出所有的回文数?
- CSS布局教程:如何用CSS构建图片、文字混排的产品展示
- WPF 如何将软件的所有图片保存在DLL内供主程序调用
- asp.net 如何读取文件夹下所有图片名称
- 如何读取某个指定文件夹下所有文件,并筛选出其中的图片文件(jpeg,bmp)展示出来。