Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Forked from thagxt/rename-file.php
Last active February 1, 2019 16:56
Show Gist options
  • Save Alexander-Pop/175723950118a7fa2c6f3a698413e8d2 to your computer and use it in GitHub Desktop.
Save Alexander-Pop/175723950118a7fa2c6f3a698413e8d2 to your computer and use it in GitHub Desktop.
Quickly rename a file name with PHP. w/ error handling #php #file
<?php
$oldname = "index.html";
$newname = "index.php";
// checking if file exist or not.
if ( file_exists($oldname) && ( (!file_exists($newname))|| is_writable($newname) ) ) {
$renameResult = rename($oldname, $newname);
die($oldname . " renamed to " . $newname);
} else {
die('nothing to rename.');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment