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