日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

PHP无用图片清理,php – 如何在img / p /上删除Prestashop无用的图像

發(fā)布時間:2023/12/18 php 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP无用图片清理,php – 如何在img / p /上删除Prestashop无用的图像 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在Prestashop,當(dāng)我刪除一些產(chǎn)品時,圖像保留在他們的目錄/ img / p / so,此時我的圖像目錄接近2GB.

找到這個腳本來刪除Prestashop上無用的和BBDD未鏈接的圖像,但我不知道為什么它只檢測孤立圖像但不刪除它們.也許在php配置上禁用unlink功能?可能嗎?或者代碼錯了?還有另一種方法可以進(jìn)行這種清理嗎?

// root path of the shop

$shop_root='/home/myweb/public_html/';

// limit number of image files to check, set to 10 for testing

$limit=1000000000;

include $shop_root . '/config/settings.inc.php';

$pdo = new PDO( 'mysql:host='._DB_SERVER_.';dbname='._DB_NAME_, _DB_USER_, _DB_PASSWD_ );

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$r=$pdo->query('select count(1) cnt from ps_image')->fetch();

echo 'count images database: '.$r['cnt'] . "
";

// reset some counters

$cnt_files=0;

$cnt_checked=0;

$cnt_not_found=0;

$cnt_found=0;

for($ii=1; ($ii<=9) && ($cnt_files != $limit); $ii++)

{

$path=$shop_root.'img/p/'.$ii;

delImage($path);

for($jj=0; ($jj<=9) && ($cnt_files != $limit); $jj++)

{

$path=$shop_root.'img/p/'.$ii.'/'.$jj;

delImage($path);

for($kk=0; ($kk<=9) && ($cnt_files != $limit); $kk++)

{

$path=$shop_root.'img/p/'.$ii.'/'.$jj.'/'.$kk;

delImage($path);

for($ll=0; ($ll<=9) && ($cnt_files != $limit); $ll++)

{

$path=$shop_root.'img/p/'.$ii.'/'.$jj.'/'.$kk.'/'.$ll;

delImage($path);

}

}

}

}

echo 'files: '.$cnt_files.' checked: '.$cnt_checked.' not_found: '.$cnt_not_found.' found: '.$cnt_found;

function delImage($imageDir)

{

global $limit, $pdo, $cnt_files, $cnt_checked, $cnt_not_found, $cnt_found;

if ($handle = @opendir($imageDir)) { //@ is wriiten to avoid warning message and is handled in else condition

echo $imageDir."
";

while ($cnt_files != $limit && false !== ($entry = readdir($handle))) {

if ($entry != "." && $entry != "..") {

$cnt_files++;

$pi = explode('-',$entry);

if($pi[0]>0 && !empty($pi[1])) {

$cnt_checked++;

if(!checkExistsDb($pdo,$pi[0])) {

$cnt_not_found++;

echo 'rm '.$imageDir.'/'.$entry."
";

unlink($imageDir.'/'.$entry);

} else {

$cnt_found++;

}

}

}

}

closedir($handle);

}

else

{

echo $imageDir." doesn't exist".'
';

}

}

function checkExistsDb($pdo, $id_image) {

$r=$pdo->query($q='select \'ok\' ok, (select id_image from ps_image where id_image = '.(int)$id_image.') id_image');

$row=$r->fetch();

if($row['ok']!='ok') die( 'Problem with query, please correct');

return $row['id_image']?true:false;

}

?>

這是一個輸出部分:

/home/myweb/public_html/img/p/9/9/7

/home/myweb/public_html/img/p/9/9/7/0 doesn't exist

/home/myweb/public_html/img/p/9/9/7/1 doesn't exist

/home/myweb/public_html/img/p/9/9/7/2 doesn't exist

/home/myweb/public_html/img/p/9/9/7/3 doesn't exist

/home/myweb/public_html/img/p/9/9/7/4 doesn't exist

/home/myweb/public_html/img/p/9/9/7/5 doesn't exist

/home/myweb/public_html/img/p/9/9/7/6 doesn't exist

/home/myweb/public_html/img/p/9/9/7/7 doesn't exist

/home/myweb/public_html/img/p/9/9/7/8 doesn't exist

/home/myweb/public_html/img/p/9/9/7/9 doesn't exist

/home/myweb/public_html/img/p/9/9/8

/home/myweb/public_html/img/p/9/9/8/0 doesn't exist

/home/myweb/public_html/img/p/9/9/8/1 doesn't exist

/home/myweb/public_html/img/p/9/9/8/2 doesn't exist

/home/myweb/public_html/img/p/9/9/8/3 doesn't exist

/home/myweb/public_html/img/p/9/9/8/4 doesn't exist

/home/myweb/public_html/img/p/9/9/8/5 doesn't exist

/home/myweb/public_html/img/p/9/9/8/6 doesn't exist

/home/myweb/public_html/img/p/9/9/8/7 doesn't exist

/home/myweb/public_html/img/p/9/9/8/8 doesn't exist

/home/myweb/public_html/img/p/9/9/8/9 doesn't exist

/home/myweb/public_html/img/p/9/9/9

/home/myweb/public_html/img/p/9/9/9/0 doesn't exist

/home/myweb/public_html/img/p/9/9/9/1 doesn't exist

/home/myweb/public_html/img/p/9/9/9/2 doesn't exist

/home/myweb/public_html/img/p/9/9/9/3 doesn't exist

/home/myweb/public_html/img/p/9/9/9/4 doesn't exist

/home/myweb/public_html/img/p/9/9/9/5 doesn't exist

/home/myweb/public_html/img/p/9/9/9/6 doesn't exist

/home/myweb/public_html/img/p/9/9/9/7 doesn't exist

/home/myweb/public_html/img/p/9/9/9/8 doesn't exist

/home/myweb/public_html/img/p/9/9/9/9 doesn't exist

files: 29013 checked: 22290 not_found: 0 found: 22290

總結(jié)

以上是生活随笔為你收集整理的PHP无用图片清理,php – 如何在img / p /上删除Prestashop无用的图像的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。