Перейти к содержимому


lipu4ka

Регистрация: 02 Oct 2012
Offline Активность: Nov 03 2014 04:45 PM
-----

Мои темы

Три скрипта проверки наличия изображений

03 January 2014 - 11:15 PM

1. Скрипты в корень сайта
2. lostphoto.php - список товаров у которых нет файлов-фотографий
3. nophoto.php - список товаров у которых не заведены фото
4. movephoto.php - список файлов-фотографий, которые не привязаны к товарам.
Для перемещения этих файлов в категорию вида YYMMDD использовать movephoto.php?move=yes

lostphoto.php
<?
header('Content-type: text/html; charset="utf-8"',true);
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?
include ('core/config/connect.inc.php');
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die (mysql_error());
mysql_select_db(DB_NAME) or die (mysql_error());
mysql_query("set character_set_client ='utf8'");
mysql_query("set character_set_results ='utf8'");
mysql_query("set collation_connection ='utf8_general_ci'");
function GetPicturesRow($productID,$photoID) {
$q = "select * from ".DB_PRFX."product_pictures where productID='".(int)$productID."' and photoID='".(int)$photoID."'";
$r=mysql_query($q);
$row=mysql_fetch_array($r);
return $row;
}
function file_exists_case($strUrl)
{
$strUrl=$_SERVER['DOCUMENT_ROOT'] .'/'.$strUrl;
$realPath = str_replace('\\','/',realpath($strUrl));
if(file_exists($strUrl) && $realPath == $strUrl)
{
return 1;//File exists, with correct case
}
elseif(file_exists($realPath))
{
return 2;//File exists, but wrong case
}
else
{
return 0;//File does not exist
}
}
$q="select * from ".DB_PRFX."products where default_picture>0 order by productID";
$r=mysql_query($q);
$col=0;
$out='<h1>Список товаров с отсутствующим файлом изображения</h1><table><tr class="thead"><td class="id">ID</td><td class="Article">Артикул</td><td class="usd">Исп</td><td class="name">Название</td><td class="pic">Файл</td></tr>';
while ($row=mysql_fetch_array($r)) {
$fail='';
$pictire_row=GetPicturesRow($row["productID"],$row["default_picture"]);
if ($pictire_row['filename']<>'') {
if (file_exists_case('data/small/'.$pictire_row['filename'])==0) $fail.='<div>Отсутствует файл data/small/'.$pictire_row['filename'].'</div>';
if (file_exists_case('data/small/'.$pictire_row['filename'])==2) $fail.='<div>Неверный регистр файла data/small/'.$pictire_row['filename'].'</div>';
}
if ($pictire_row['thumbnail']<>'') {
if (file_exists_case('data/medium/'.$pictire_row['thumbnail'])==0) $fail.='<div>Отсутствует файл data/medium/'.$pictire_row['thumbnail'].'</div>';
if (file_exists_case('data/medium/'.$pictire_row['thumbnail'])==2) $fail.='<div>Неверный регистр файла data/medium/'.$pictire_row['thumbnail'].'</div>';
}
if ($pictire_row['enlarged']<>'') {
if (file_exists_case('data/big/'.$pictire_row['enlarged'])==0) $fail.='<div>Отсутствует файл data/big/'.$pictire_row['enlarged'].'</div>';
if (file_exists_case('data/big/'.$pictire_row['enlarged'])==2) $fail.='<div>Неверный регистр файла data/big/'.$pictire_row['enlarged'].'</div>';
}
if ($fail<>'') { $out.='<tr><td>'.$row["productID"].'</td><td>'.$row["product_code"].'</td><td>'.$row["enabled"].'</td><td>'.$row["name"].'</td><td>'.$fail.'</td></tr>'; $col++; }
}
if ($col==0) $out.='<tr><td colspan="3" class="center red">Нет товаров</td></tr>'; else $out.='<tr class="thead"><td colspan="3">Всего: '.$col.'</td></tr>';
$out.='</table>';
echo $out;
?>
<style>
table { width:100%; border-left:1px solid #999999;border-top:1px solid #999999; margin:0px; padding:0px; outline: none; border-collapse: collapse;}
table td { padding:5px; border-bottom:1px solid #999999;border-right:1px solid #999999; font-size:12px;}
.thead td { background:#cccccc; font-weight:700; font-size:14px !important;}
.center { text-align:center;}
.red { color:#FF0000;}
</style>



nophoto.php
<?
header('Content-type: text/html; charset="utf-8"',true);
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?
include ('core/config/connect.inc.php');
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die (mysql_error());
mysql_select_db(DB_NAME) or die (mysql_error());
mysql_query("set character_set_client ='utf8'");
mysql_query("set character_set_results ='utf8'");
mysql_query("set collation_connection ='utf8_general_ci'");

$q="select * from ".DB_PRFX."products where default_picture IS NULL order by productID";
$r=mysql_query($q);
$col=mysql_num_rows($r);
$out='<h1>Список товаров без изображения</h1><table><tr class="thead"><td class="id">ID</td><td class="Article">Артикул</td><td class="usd">Исп</td><td class="name">Название</td></tr>';
while ($row=mysql_fetch_array($r)) {
$out.='<tr><td>'.$row["productID"].'</td><td>'.$row["product_code"].'</td><td>'.$row["enabled"].'</td><td>'.$row["name"].'</td></tr>';
}
if ($col==0) $out.='<tr><td colspan="2" class="center red">Нет товаров без изображения</td></tr>'; else $out.='<tr class="thead"><td colspan="2">Всего: '.$col.'</td></tr>';
$out.='</table>';
echo $out;
?>
<style>
table { width:100%; border-left:1px solid #999999;border-top:1px solid #999999; margin:0px; padding:0px; outline: none; border-collapse: collapse;}
table td { padding:5px; border-bottom:1px solid #999999;border-right:1px solid #999999; font-size:12px;}
.thead td { background:#cccccc; font-weight:700; font-size:14px !important;}
.center { text-align:center;}
.red { color:#FF0000;}
</style>



movephoto.php
<?
header('Content-type: text/html; charset="utf-8"',true);
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?
include ('core/config/connect.inc.php');
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die (mysql_error());
mysql_select_db(DB_NAME) or die (mysql_error());
mysql_query("set character_set_client ='utf8'");
mysql_query("set character_set_results ='utf8'");
mysql_query("set collation_connection ='utf8_general_ci'");

$now=date('Ymd',time());

function findInDir($directory,$arr)
{
global $now, $col;
$moveto=$directory."/".$now;
$files = scandir($directory);
foreach($files as $file) {
if(is_file($directory."/".$file) && file_exists($directory."/".$file)) {
if (!in_array($file,$arr) && $file<>'index.html') {
echo '<tr><td>'.$directory.'</td><td>'.$file.'</td><td>'.$moveto.'</td></tr>';
$col++;
if ($_GET["move"]=='yes') {
if (!file_exists($moveto)) mkdir($moveto, 0777);
rename($directory."/".$file,$moveto."/".$file);
}
}
}
}
}

$q="select * from ".DB_PRFX."product_pictures";
$r=mysql_query($q);
$pis_filename=array();
$pis_thumbnail=array();
$pis_enlarged=array();
while ($pictire_row=mysql_fetch_array($r)) {
if ($pictire_row['filename']<>'') $pis_filename[]=$pictire_row['filename'];
if ($pictire_row['thumbnail']<>'') $pis_thumbnail[]=$pictire_row['thumbnail'];
if ($pictire_row['enlarged']<>'') $pis_enlarged[]=$pictire_row['enlarged'];
}
echo '<h1>Список файлов для переноса</h1><div class="desc">Запуск скрипта с ключем move=yes приведет к реальному переносу файлов!</div><table><tr class="thead"><td class="folder">Папка</td><td class="pic">Файл</td><td class="pic">Куда перенесен</td></tr>';
$col=0;
findInDir($_SERVER['DOCUMENT_ROOT'].'/data/small',$pis_filename);
findInDir($_SERVER['DOCUMENT_ROOT'].'/data/medium',$pis_thumbnail);
findInDir($_SERVER['DOCUMENT_ROOT'].'/data/big',$pis_enlarged);

if ($col==0) echo '<tr><td colspan="3" class="center red">Нет файлов для переноса</td></tr>'; else echo '<tr class="thead"><td colspan="3">Всего: '.$col.'</td></tr>';
echo '</table>';
?>
<style>
table { width:100%; border-left:1px solid #999999;border-top:1px solid #999999; margin:0px; padding:0px; outline: none; border-collapse: collapse;}
table td { padding:5px; border-bottom:1px solid #999999;border-right:1px solid #999999; font-size:12px;}
.thead td { background:#cccccc; font-weight:700; font-size:14px !important;}
.center { text-align:center;}
.red { color:#FF0000;}
.desc { color:#333333; font-size:12px; padding-bottom:15px;}
</style>