PHP无用图片清理,php – 如何在img / p /上删除Prestashop无用的图像
在Prestashop,当我删除一些产品时,图像保留在他们的目录/ img / p / so,此时我的图像目录接近2GB.
找到这个脚本来删除Prestashop上无用的和BBDD未链接的图像,但我不知道为什么它只检测孤立图像但不删除它们.也许在php配置上禁用unlink功能?可能吗?或者代码错了?还有另一种方法可以进行这种清理吗?
// 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
PHP无用图片清理,php – 如何在img / p /上删除Prestashop无用的图像相关推荐
- 如何在Mac电脑上删除APFS分区?
Apple File System,通常称为APFS,拥有大量新功能.由于它是一个新的文件系统,许多用户发现很难对其执行基本操作.那么如何在Mac电脑上删除APFS分区呢,有需要的小伙伴欢迎参考! 开 ...
- PHP无用图片清理,DNUI Delete not used image无用图片删除插件介绍及使用方法 | 很文博客...
最近有一些用户反馈,在网站空间的upload文件夹中所上传的图片,都会被生成非常多不同尺寸的,有的用户的网站空间很小,因此这些略缩图占用了一些储存空间. wordpress是会自动生成不同尺寸的略缩图 ...
- wm_paint重绘图像_如何在Windows 10上使用Paint 3D调整图像大小
wm_paint重绘图像 If you need to perform a simple task like resizing an image on your Windows 10 PC, you ...
- html画布图片不显示_如何在HTML5画布上显示图像
html画布图片不显示 by Nash Vail 由Nash Vail Ok, so here's a question: "Why do we need an article for th ...
- win7查找计算机图片,如何在 win7电脑上查看 HEIC 照片的内容?
原标题:如何在 win7电脑上查看 HEIC 照片的内容? 如何在 win7电脑上查看 HEIC 照片的内容? HEIC是iOS 11更新后,iPhone 7及其后硬件,在拍摄照片时的默认图像存储格式 ...
- Python将图片转化为base64编码以及如何在html网页上显示
1.Python将图片转化为base64编码 test.py # -*- coding: utf-8 -*- import base64 #这一段代码时间图片转化为base64 with open(& ...
- 如何在Windows cmd上递归删除文件或文件夹?批量删除指定大小的图片文件
如何在Windows cmd上递归删除文件或文件夹? for /r %R in (.gif) do if exist %R (rd /s /q "%R") / q禁用是/否提示 / ...
- iphone.android下载,如何在iPhone和Android上删除下载
每当您从网站下载文件时,它都会保存在您的设备上,直到您将其删除为止. 无论您使用计算机还是智能手机,内部存储都是有限的,您需要删除设备上的下载以释放空间. iPhone,Android,Windows ...
- 小程序影藏溢出的gif_如何在Android手机上快速实现视频转GIF动图呢?
毫无疑问,Android是目前使用最广泛的手机系统.GIF很有趣,并且比视频占用更少的存储容量.本文将向您介绍如何在Android手机上快速转GIF动图的多种方法. [官网]万兴优转 - 顶尖音视频格 ...
最新文章
- R语言ggplot2可视化:在选定数据点周围添加圆圈(Add Circles Around Select Data Points)
- [2018-08-03] python开发个人资源共享网--第一天
- hdu 3333 树状数组+离线处理
- Bicolored RBS
- 服务器安装系统教程进光盘界面,iso光盘系统怎么安装系统教程
- delphi 停电文本数据丢失_河南照片数据恢复怎么联系
- DX中材质不能正确显示的问题(要么黑色,要么白色)
- java 调用 cplex
- 正运动控制固件升级问题记录
- HTML - 空链接
- 代理服务器关闭没过多久又自动开启,Win10自动更新关闭了过几天又自动开启了怎么办?...
- 华三交换机升级的ipe文件_H3C 交换机升级说明
- 如何在网上赚钱,也可以在家兼职赚钱的5个网上项目分享给大家
- Android 全面屏处理(适配挖孔屏、刘海屏) kotlin
- autoware.auto安装教程
- 开通共享毛巾机小程序
- python爬虫入门—selenuim自动登录qq邮箱
- 2021年4月14日 星期三 晴
- Esp8266进阶之路12 图文并茂学习阿里云主机搭建8266MQTT服务器,实现移动网络远程控制一盏灯!
- 幸运通过系统集成项目管理工程师的6条经验
热门文章
- sqlserver查询当月的每一天_SQL生成一年每一天的时间列表的几种方法
- 来,看看这20个常用的宏定义!
- 2020年9月编程语言排行榜:C语言继续第一,你站哪个?
- 「第一篇」大学生电子设计竞赛,等你来提问。
- 目前最常用的计算机机箱类型为_绍兴承接离心风机箱高品质
- iphone打字怎么换行_除了打字,iPhone的键盘还有这12个功能
- 字符定长文件Linux怎么生成,Linux中的more命令-逐页显示长文本文件
- python查找最长公共前缀_Python实现查找字符串数组最长公共前缀示例
- 【Docker系列教程之一】docker入门
- JS里的时间有关的标签