Return to Snippet

Revision: 8375
at September 17, 2008 14:57 by section31


Initial Code
function rename_if_exists($dir, $filename) {
	$ext = strrchr($filename, '.');
	$prefix = substr($filename, 0, -strlen($ext));
	
	$i = 0;
	while(file_exists($dir . $filename)) { // If file exists, add a number to it.
		$filename = $prefix . ++$i . $ext;
	}

	return $filename;
}

Initial URL

                                

Initial Description

                                

Initial Title
Rename File If Exists

Initial Tags

                                

Initial Language
PHP