Skip to content

Instantly share code, notes, and snippets.

@janstieler
Created February 23, 2021 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janstieler/593b49d9146ea3b4130ebca4147e4f79 to your computer and use it in GitHub Desktop.
Save janstieler/593b49d9146ea3b4130ebca4147e4f79 to your computer and use it in GitHub Desktop.
PHP Rename Files in Folder
<?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