tryingtolearn Posted July 19, 2008 Share Posted July 19, 2008 Hi All I am trying to use rename() to take all the images in one directory that have a timestamp and filename and rename them to a new directory but change the names to 1.jpg, 2.jpg, 3.jpg etc... But by using this, it only renames the last one. if ($handle = opendir('./friends')) { while (false !== ($lv = readdir($handle))) { if ($lv != "." && $lv != "..") { $root = getcwd(); $limit = count(glob('./friends/*.*')); //just * to count subdirs for ($i = 1; $i <= $limit; $i++) { copy("./friends/$lv", "$root/friends_no/$i.jpg"); } } } closedir($handle); } Anybody have an idea on what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/115542-rename-using-consecutive-numbers/ Share on other sites More sharing options...
MasterACE14 Posted July 19, 2008 Share Posted July 19, 2008 EDIT: nvm, my mistake. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/115542-rename-using-consecutive-numbers/#findComment-593988 Share on other sites More sharing options...
tryingtolearn Posted July 19, 2008 Author Share Posted July 19, 2008 Nevermind, I figured it out $ct = "1"; if ($handle = opendir('./friends')) { while (false !== ($lv = readdir($handle))) { if ($lv != "." && $lv != "..") { $limit = count(glob('./friends/*.*')); $up =$ct++; $root = getcwd(); copy("./friends/$lv", "$root/friends_no/$up.jpg"); } } closedir($handle); } Quote Link to comment https://forums.phpfreaks.com/topic/115542-rename-using-consecutive-numbers/#findComment-594071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.