Home >Backend Development >PHP Tutorial >PHP code to remove duplicate image files

PHP code to remove duplicate image files

WBOY
WBOYOriginal
2016-07-25 08:55:371320browse
  1. /**

  2. * Remove duplicate image files
  3. * by bbs.it-home.org
  4. */
  5. exec("find . -type f", $lines);

  6. $arr = array();

  7. $del = array();

  8. $n = 0;

  9. foreach($lines as $line){
  10. $line = trim($line);
  11. if(!$line){
  12. continue;
  13. }
  14. $n ++;
  15. $md5 = md5_file($line);

  16. if(isset($arr[$md5])){

  17. $del[] = $line;
  18. //echo "$n del $linen";
  19. unlink("{$line}");
  20. }else{
  21. $arr[$md5] = 1;
  22. }
  23. }

  24. echo "del " . count($del) . " filesn";

  25. //echo join("n", $del);

复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn