Created
December 27, 2010 22:46
-
-
Save niczak/756659 to your computer and use it in GitHub Desktop.
Randomizes image file names in current directory for use w/ digital frames that don't support shuffle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment