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? 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 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); } Link to comment https://forums.phpfreaks.com/topic/115542-rename-using-consecutive-numbers/#findComment-594071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.