<?php /** * * @ 批量刪除Zen Cart 無圖片商品 * @ 使用方法: 將本文件上傳到網站根目錄下運行 http://你的域名/zcdelpro.php * @ $status = 'delete'; //刪除沒有圖片的產品 * @ $status = 'hide'; //下架沒有圖片的產品 * @ $status = 'default'; //列出沒有圖片的產品
* @ 做者QQ: 631992791 * */ $status = 'default'; $no_img_id = array(); require("includes/application_top.php"); $pro_list = $db->Execute("select products_id, products_image from ".TABLE_PRODUCTS); while (!$pro_list->EOF){ if(file_exists(DIR_WS_IMAGES.$pro_list->fields['products_image']) && filesize(DIR_WS_IMAGES.$pro_list->fields['products_image']) > 0 && preg_match('/.*\.(jpg|bmp|gif|png)$/Uis', $pro_list->fields['products_image'])) { //echo 'ID爲 '.$products_list->fields['products_id'].' 的產品圖片正常<br />'; }else{ if($status == 'delete'){ $db->Execute('delete from '.TABLE_PRODUCTS. ' where products_id='.$pro_list->fields['products_id']); $db->Execute('delete from '.TABLE_PRODUCTS_ATTRIBUTES. ' where products_id='.$pro_list->fields['products_id']); $db->Execute('delete from '.TABLE_PRODUCTS_DESCRIPTION. ' where products_id='.$pro_list->fields['products_id']); $db->Execute('delete from '.TABLE_PRODUCTS_TO_CATEGORIES. ' where products_id='.$pro_list->fields['products_id']); echo 'ID爲 '.$pro_list->fields['products_id'].' 產品已刪除<br />'; }elseif($status == 'hide'){ $db->Execute('update '.TABLE_PRODUCTS. ' set products_status = 0 where products_id='.$pro_list->fields['products_id']); echo 'ID爲 '.$pro_list->fields['products_id'].' 產品已下架<br />'; }else{ $no_img_id[] = $pro_list->fields['products_id']; echo 'ID爲 '.$pro_list->fields['products_id'].' 產品無圖片<br />'; } } $pro_list->MoveNext(); } if($status != 'delete' && $status != 'hide'){ echo '<span style="color:#090;">刪除沒有圖片的產品請將第10行改成 $status = "delete";<br />下架沒有圖片的產品請將第10行改成 $status = "hide";<br /></span>'; if(count($no_img_id)>0){ echo '沒有圖片的產品列表:<br />'; foreach($no_img_id as $id){ echo '<a href="http://'.$_SERVER['HTTP_HOST'].DIR_WS_CATALOG.'index.php?main_page=product_info&products_id='.$id.'" target="_blank">查看ID爲'.$id.'的產品</a><br />'; } } } ?>