由于图片过多,占用很多无用空间,想把没用的图片删除了。首先导出了一份数据库文件.sql,存放在/data目录中。
LostPictures.php
abc.php
img_dir = $img_dir; $this->sql_dir = $sql_dir; } //丢失与无用的图片列表 public function lostList(){ header("Content-type: text/html; charset=utf-8"); $sql_fiel = ABSPATH . $this->sql_dir; if(is_array($this->img_dir)){ foreach($this->img_dir as $val){ $this->searchDir(ABSPATH . '/' . $val ,$this->lost_img); } }else{ $this->searchDir(ABSPATH . '/' . $this->img_dir ,$this->lost_img); } if(file_exists($sql_fiel)){ $array = array(); $content = file_get_contents($sql_fiel); $content = str_replace('\\\\\\', '', $content); //百度编辑器中...title=\\\"1467862183958179.jpg\\\"...alt=\\\"腰椎间盘突出.jpg\\\" $patt = '/[\'"][\/]?([^0-9][a-zA-Z0-9_\/]*?\.(?:jpg|png|gif|jpeg))[\'"]/';//不以数字、不是中文的图片路径 preg_match_all($patt, $content, $mat); for($i=0;$i lost_img);$i++){ if(substr($this->lost_img[$i],-3)=='jpg'||substr($this->lost_img[$i],-3)=='png'||substr($this->lost_img[$i],-3)=='gif'||substr($this->lost_img[$i],-3)=='jpeg'){ if(!in_array($this->lost_img[$i],array_values($mat[1]))){ $array['无用'][] = $this->lost_img[$i]; //文件夹中无用的数据图片 } } } echo " ";exit; //打印出丢失与无用的图片 }else{ echo 'sql文件不存在'; } } //读取目录及子目录下所有文件名 private function searchDir($path,&$data){ if(is_dir($path)){ $dp=dir($path); while($file=$dp->read()){ if($file!='.'&& $file!='..'&& $file!='.svn'){ $this->searchDir($path.'/'.$file,$data); } } $dp->close(); } if(is_file($path)){ $data[]=$path; } } }
".print_r($array,true)."
abc.php
lostList();