Created
February 23, 2021 23:13
-
-
Save janstieler/593b49d9146ea3b4130ebca4147e4f79 to your computer and use it in GitHub Desktop.
PHP Rename Files in Folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dir = 'images/'; | |
$files = scandir($dir); | |
foreach($files as $i => $name) { | |
if($i > 2){ | |
$filename = $name; | |
$newname = $i-2 . '_' . $filename; | |
if ($newname != $filename) { | |
rename($dir.$filename, $dir.$newname); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment