统计服务器站点上丢失与删除无用的图片

由于图片过多,占用很多无用空间,想把没用的图片删除了。首先导出了一份数据库文件.sql,存放在/data目录中。
LostPictures.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();



 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值