Created
February 13, 2014 10:06
-
-
Save gothedistance/8972668 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
function renameForWelcartImage ( $path ) { | |
if (is_dir($path) === false) { | |
echo 'not directory path'; | |
exit(); | |
} | |
$file = scandir($path); | |
$count = 0; | |
foreach($file as $key){ | |
if ('.' == $key || '..' == $key) { continue; } | |
$result = $path.'/'.$key; | |
if (is_dir($result)) { | |
$count = 0; | |
renameForWelcartImage($result); | |
} elseif (is_file($result)) { | |
$path_info = pathinfo($result); | |
$d_tree = explode('/',$path_info['dirname']); | |
$fileName = $d_tree[count($d_tree) -1]; | |
$count++; | |
$rename_fileName = ''; | |
if($count == 1) { | |
$rename_fileName = $path_info['dirname'].'/'.$fileName.".".$path_info['extension']; | |
} else { | |
$suffix = str_pad($count-1, 3, "0", STR_PAD_LEFT); | |
$rename_fileName = $path_info['dirname'].'/'.$fileName."-".$suffix.".".$path_info['extension']; | |
} | |
rename($result,$rename_fileName); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment