Rename Multiple Image files and others files using php
<?php
$i=1;
// opens images folder
$a="kolo/ShotGlass";
if ($handle = opendir($a)) {
while (false !== ($file = readdir($handle))) {
// strips files extensions
$crap= array(".jpg", ".jpeg", ".JPG", ".JPEG", ".png", ".PNG", ".gif", ".GIF", ".bmp", ".BMP", "_", "-");
$newstring = str_replace($crap," ", $file );
//asort($file, SORT_NUMERIC); - doesnt work :(
// hides folders, writes out ul of images and thumbnails from two folders
if ($file != "." && $file != ".." && $file != "index.php" && $file != "Thumbnails" && $file!="popup" && $file!="popup-orignal") {
$list=explode(".",$file);
$myfile= str_replace("-copy","", $list[0]);
$myfile=$myfile.'.'.$list[1];
$oldfile=$a.'/'.$file;
$new=$a.'/'.$myfile;echo "<br/>";
rename($oldfile, $new);
$i++;
}
}
closedir($handle);
}
?>
Comments
Post a Comment