[Solved] loop and rename all subfolders in php

[ad_1]

If I’m correct about the first line of code here you sholud get an array lookin like the second line. Test that first and make a backup of your files.

This should list all userid’s or directories and loop through them.
If the copy is success (true) it unlinks the old file, else returns a error message.

This is untested code

//$arr = array_filter(glob('images/logos/*'), 'is_dir');
$arr = array("images/logos/1216","images/logos/11437","images/logos/234438");
//var_dump($arr);

foreach($arr as $dir){
    $UID = str_replace("images/logos/", "", $dir);
    $newpath = "images/users/" . floor($UID/1000) . "https://stackoverflow.com/" . $UID . "/logos/logo.jpg";
    $oldpath = $dir . "/logo.jpg";
    if(copy($oldpath, $newpath)){
        unlink($oldpath);
    }else{
        echo "error with file " . $oldpath . "<br>\n";
        $error = true;
    }
}

if(!$error) unlink("images/logos");

EDIT; Just noticed I had used Excel too much lately. Changed the & to .
EDIT2; tested the code on my own page now and it seems the glob returns the path. Included code to get the UserID.

7

[ad_2]

solved loop and rename all subfolders in php