#!/usr/bin/php -q paypal@thedrewerys.com //-Dustin Drewery //************* CONFIG *******************/ //Set the folder to look for pics in. (no /) $dir = $_POST["dir"]; //Set the maximum number of pics for each dir $max = $_POST["max"]; //Where do you want to save them? (no /) // MAKE SURE THIS EXISTS AND IS CHMOD 777!! //Don't put it in the same folder as your originals either.. $copyPath = $_POST["copyPath"]; //Prefix, if any, to add to the folder name.. new folder names will be prefix1 prefix2 prefix3... $prefix = $_POST["prefix"]; //List of prefixes to copy.. ALL CAPS $fileTypes = $prefix = $_POST["fileTypes"]; //Thats it!!! //******* You shouldn't need to edit below this line ***********************/ CopyDirContents($dir,$max,$fileTypes,$copyPath,$prefix); function CopyDirContents($dir,$max,$fileTypes,$copyPath,$prefix=null){ ini_set("max_execution_time",6000); if (!is_dir($dir)){die ("Error::Not a directory: $dir!");} $totalFiles = 0; $dirNum = 0; $cur = 1; $curDir = $copyPath."/".$prefix.$dirNum; mkdir($curDir); if ($root=@opendir($dir)){ while ($file=readdir($root)){ if($file=="." || $file==".."){continue;} if(is_dir($dir."/".$file)){ continue; }else{ $fileParts = explode(".",$file); if(!is_array($fileParts) || !in_array(strtoupper($fileParts[count($fileParts)-1]),$fileTypes)) {continue;} if($cur > $max) { $dirNum++; $curDir = $copyPath."/".$prefix.$dirNum; mkdir($curDir); $cur = 1; } copy($dir."/".$file,$curDir."/".$file); print $file."\t\t\t=>\t".$curDir."/".$file."\n"; $cur++; $totalFiles++; } } } print "\nCopied $totalFiles files into ".$dirNum." directories.\n"; } ?>