Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- randomfile.php
- A quickie script that will take all images in
- current directory, back them up to ./Orig and
- rename all files in parent directory w/ random
- numbers.
- Written: 12/27/2010 - Nicholas Kreidberg
- Revised: 12/27/2010 - Nicholas Kreidberg
- */
- $dir = "./";
- $bu = "Orig/";
- $atypes = array("jpg", "gif", "png");
- if(is_dir($dir))
- {
- if($dh = opendir($dir))
- {
- $i = 0;
- if(!is_dir($dir.$bu))
- mkdir($dir.$bu);
- while(($file = readdir($dh)))
- {
- if(is_file($file) && (in_array(pathinfo($file, PATHINFO_EXTENSION), $atypes)))
- {
- echo "Filename: $file backed-up and renamed.\n";
- copy($file, $dir.$bu.$file);
- $newfile = rand(1, 99999999).'.'.pathinfo($file, PATHINFO_EXTENSION);
- rename($file, $newfile);
- $i++;
- }
- }
- closedir($dh);
- echo "$i files processed.\n\n";
- }
- }
- ?>
Add Comment
Please, Sign In to add comment