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 Link to comment https://forums.phpfreaks.com/topic/155934-functionrename-file-exists/ Share on other sites More sharing options...
hellonoko Posted April 28, 2009 Share Posted April 28, 2009 Show your code please? Link to comment https://forums.phpfreaks.com/topic/155934-functionrename-file-exists/#findComment-820902 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 Link to comment https://forums.phpfreaks.com/topic/155934-functionrename-file-exists/#findComment-820905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.