dubc07 Posted April 28, 2009 Share Posted April 28, 2009 Is there any way of overwriting a file name if it exists. Basically i have a program which deletes a file name image3 or whatever, but i need to rename all images in the folder in line LIKE image1 image2 image3 image4 image5 but the files already exists. this is the error i get [function.rename]: File exists in C:\wamp\www\folder1\fin1_picedit.php on line 106 Quote Link to comment Share on other sites More sharing options...
hellonoko Posted April 28, 2009 Share Posted April 28, 2009 Show your code please? Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 28, 2009 Share Posted April 28, 2009 /** * Renames a file or directory. If a file or directory called $newname exists, tries to unlink it first. */ function renameWithOverwrite($oldname, $newname, $context = null) { $outcome = true; if (file_exists($newname)) { if(!unlink($newname, $context)) $outcome = false; } if(!rename($oldname, $newname, $context)) $outcome = false; return $outcome; } not tested Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.