Jump to content

Recommended Posts

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

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);
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.