public static function uniqueFilename($path) {
		// get directory
		$dir = self::getDirectory($path);

		// get filename
		$filename = self::getFileName($path);

		// sanitize the file name before we begin processing
		$filename = self::sanitizeFileName($filename);

		// separate the filename into a name and extension
		$info = pathinfo($filename);
		$ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
		$name = basename($filename, $ext);

		// edge case: if file is named '.ext', treat as an empty name
		if ( $name === $ext ) $name = '';

		// Increment the file number until we have a unique file to save in $dir.
		
		$number = '';
		// change '.ext' to lower case
		if ( $ext && strtolower($ext) != $ext ) {
			$ext2 = strtolower($ext);
			$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
			// check for both lower and upper case extension or image sub-sizes may be overwritten
			while ( Storage::has($dir . DIRECTORY_SEPARATOR . $filename) || Storage::has($dir . DIRECTORY_SEPARATOR . $filename2) ) {
				$new_number = $number + 1;
				$filename = str_replace( "$number$ext", "$new_number$ext", $filename );
				$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
				$number = $new_number;
			}
			return $filename2;
		}
		while ( Storage::has( $dir . DIRECTORY_SEPARATOR . $filename ) ) {
			if ( '' == "$number$ext" )
				$filename = $filename . ++$number . $ext;
			else
				$filename = str_replace( "$number$ext", ++$number . $ext, $filename );
		}
		return self::normalizePath($dir . DIRECTORY_SEPARATOR . $filename);
	}
public static function uniqueFilename($path) {
		// get directory
		$dir = self::getDirectory($path);

		// get filename
		$filename = self::getFileName($path);

		// sanitize the file name before we begin processing
		$filename = self::sanitizeFileName($filename);

		// separate the filename into a name and extension
		$info = pathinfo($filename);
		$ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
		$name = basename($filename, $ext);

		// edge case: if file is named '.ext', treat as an empty name
		if ( $name === $ext ) $name = '';

		// Increment the file number until we have a unique file to save in $dir.
		
		$number = '';
		// change '.ext' to lower case
		if ( $ext && strtolower($ext) != $ext ) {
			$ext2 = strtolower($ext);
			$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
			// check for both lower and upper case extension or image sub-sizes may be overwritten
			while ( Storage::has($dir . DIRECTORY_SEPARATOR . $filename) || Storage::has($dir . DIRECTORY_SEPARATOR . $filename2) ) {
				$new_number = $number + 1;
				$filename = str_replace( "$number$ext", "$new_number$ext", $filename );
				$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
				$number = $new_number;
			}
			return $filename2;
		}
		while ( Storage::has( $dir . DIRECTORY_SEPARATOR . $filename ) ) {
			if ( '' == "$number$ext" )
				$filename = $filename . ++$number . $ext;
			else
				$filename = str_replace( "$number$ext", ++$number . $ext, $filename );
		}
		return self::normalizePath($dir . DIRECTORY_SEPARATOR . $filename);
	}
public static function uniqueFilename ( $ path ) { // get directory $ dir = self :: getDirectory ( $ path ) ; // get filename $ filename = self :: getFileName ( $ path ) ; // sanitize the file name before we begin processing $ filename = self :: sanitizeFileName ( $ filename ) ; // separate the filename into a name and extension $ info = pathinfo ( $ filename ) ; $ ext = ! empty ( $ info [ 'extension' ] ) ? '.' . $ info [ 'extension' ] : '' ; $ name = basename ( $ filename , $ ext ) ; // edge case: if file is named '.ext', treat as an empty name if ( $ name === $ ext ) $ name = '' ; // Increment the file number until we have a unique file to save in $dir. $ number = '' ; // change '.ext' to lower case if ( $ ext && strtolower ( $ ext ) != $ ext ) { $ ext2 = strtolower ( $ ext ) ; $ filename2 = preg_replace ( '|' . preg_quote ( $ ext ) . '$|' , $ ext2 , $ filename ) ; // check for both lower and upper case extension or image sub-sizes may be overwritten while ( Storage :: has ( $ dir . DIRECTORY_SEPARATOR . $ filename ) || Storage :: has ( $ dir . DIRECTORY_SEPARATOR . $ filename2 ) ) { $ new_number = $ number + 1 ; $ filename = str_replace ( "$number$ext" , "$new_number$ext" , $ filename ) ; $ filename2 = str_replace ( "$number$ext2" , "$new_number$ext2" , $ filename2 ) ; $ number = $ new_number ; } return $ filename2 ; } while ( Storage :: has ( $ dir . DIRECTORY_SEPARATOR . $ filename ) ) { if ( '' == "$number$ext" ) $ filename = $ filename . ++ $ number . $ ext ; else $ filename = str_replace ( "$number$ext" , ++ $ number . $ ext , $ filename ) ; } return self :: normalizePath ( $ dir . DIRECTORY_SEPARATOR . $ filename ) ; }
Get a filename that is sanitized and unique for the given directory.

If the filename is not unique, then a number will be added to the filename
before the extension, and will continue adding numbers until the filename is
unique.

@param string $path

@return string
Get a filename that is sanitized and unique for the given directory .