Skip to content

Instantly share code, notes, and snippets.

@thagxt
Created August 10, 2015 17:29
Show Gist options
  • Save thagxt/da5ecf916d3b6d2e6c45 to your computer and use it in GitHub Desktop.
Save thagxt/da5ecf916d3b6d2e6c45 to your computer and use it in GitHub Desktop.
Quickly rename a file name with PHP. w/ error handling
<?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