Guest User

Untitled

a guest
Jul 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2. /*
  3. randomfile.php
  4. A quickie script that will take all images in
  5. current directory, back them up to ./Orig and
  6. rename all files in parent directory w/ random
  7. numbers.
  8.  
  9. Written: 12/27/2010 - Nicholas Kreidberg
  10. Revised: 12/27/2010 - Nicholas Kreidberg
  11. */
  12.  
  13. $dir = "./";
  14. $bu = "Orig/";
  15. $atypes = array("jpg", "gif", "png");
  16.  
  17. if(is_dir($dir))
  18. {
  19. if($dh = opendir($dir))
  20. {
  21. $i = 0;
  22.  
  23. if(!is_dir($dir.$bu))
  24. mkdir($dir.$bu);
  25. while(($file = readdir($dh)))
  26. {
  27. if(is_file($file) && (in_array(pathinfo($file, PATHINFO_EXTENSION), $atypes)))
  28. {
  29. echo "Filename: $file backed-up and renamed.\n";
  30. copy($file, $dir.$bu.$file);
  31. $newfile = rand(1, 99999999).'.'.pathinfo($file, PATHINFO_EXTENSION);
  32. rename($file, $newfile);
  33. $i++;
  34. }
  35. }
  36. closedir($dh);
  37. echo "$i files processed.\n\n";
  38. }
  39. }
  40. ?>
Add Comment
Please, Sign In to add comment