Posted By

el-artiste on 09/16/09


Tagged

file code images to change of extensions the lowercase


Versions (?)

Code to change the file extensions of images to lowercase


 / Published in: PHP
 

This snippet is just an upgrade to the "http://snipplr.com/view/7396/php-file-extension-case-changer/" code. This particular code works on image files... although you can just change this line [if (preg_match("/(jpg|gif|png|bmp)/",$ext)) ] to target a specific filetype. ciao! hope this piece of code can help you as it has helped me. :)

  1. <?php
  2. $root = $_GET['root'];
  3. $files = array_merge(glob("$root*.*"),glob("$root*\*.*"),glob("$root*\*\*.*"));
  4. $z=0;
  5. $x=0;
  6. for($i=0;$i<count($files);$i++) {
  7. if(stripos($files[$i],"Thumbs.db")) {
  8. unlink($files[$i]);
  9. $z++;
  10. }
  11. else {
  12. $ext = strtolower(substr($files[$i],strlen($files[$i])-3,3));
  13. if (preg_match("/(jpg|gif|png|bmp)/",$ext)) {
  14. $filename = substr($files[$i],0,strlen($files[$i])-3);
  15. $newfile = $filename.$ext;
  16. echo $ext."\n";
  17. rename($files[$i],$newfile);
  18. $x++;
  19. }
  20. }
  21. }
  22. echo "$x image files renamed. $z Thumbs.db files deleted.";
  23. ?>

Report this snippet  

You need to login to post a comment.