Remember to set the paths correctly:
$elements = scandir($dir); foreach ($elements as $key => $value) { rename($dir.'/'.$value, $dir.'/'.$newname); }
To be less abstract, suppose $ dir is something like "/ home / someuser / somefiles" and your script is on the page /var/www/script.php, you get all the files (for example, " oldname.txt ") from scandir ($ dir), so the absolute path to the file is" /home/someuser/somefiles/oldname.txt ", but you pass" ./oldname.txt "to the rename function, which is actually" /var/www/oldname.txt "
source share