protected function incrementConflictingPath($path)
    {
        $isDir = $this->pathIsDirectory($path);
        $expPath = explode(DIRECTORY_SEPARATOR, $path);
        $oldFileName = array_pop($expPath);
        $basePath = implode(DIRECTORY_SEPARATOR, $expPath);
        if ($isDir) {
            //for directories append incremented number after underscore
            $i = 1;
            while (file_exists($newFileName = $basePath.DIRECTORY_SEPARATOR.$oldFileName."_".$i)) {
                $i++;
            }
        } else {
            //for files insert incremented number between filename and extension
            $exp = explode(".", $oldFileName);
            $extension = array_pop($exp);
            $name = implode(".", $exp);
            $i = 1;
            while (file_exists($newFileName = $basePath.DIRECTORY_SEPARATOR.$name.".".$i.".".$extension)) {
                $i++;
            }
        }

        return $newFileName;
    }
protected function incrementConflictingPath($path)
    {
        $isDir = $this->pathIsDirectory($path);
        $expPath = explode(DIRECTORY_SEPARATOR, $path);
        $oldFileName = array_pop($expPath);
        $basePath = implode(DIRECTORY_SEPARATOR, $expPath);
        if ($isDir) {
            //for directories append incremented number after underscore
            $i = 1;
            while (file_exists($newFileName = $basePath.DIRECTORY_SEPARATOR.$oldFileName."_".$i)) {
                $i++;
            }
        } else {
            //for files insert incremented number between filename and extension
            $exp = explode(".", $oldFileName);
            $extension = array_pop($exp);
            $name = implode(".", $exp);
            $i = 1;
            while (file_exists($newFileName = $basePath.DIRECTORY_SEPARATOR.$name.".".$i.".".$extension)) {
                $i++;
            }
        }

        return $newFileName;
    }
protected function incrementConflictingPath ( $ path ) { $ isDir = $ this -> pathIsDirectory ( $ path ) ; $ expPath = explode ( DIRECTORY_SEPARATOR , $ path ) ; $ oldFileName = array_pop ( $ expPath ) ; $ basePath = implode ( DIRECTORY_SEPARATOR , $ expPath ) ; if ( $ isDir ) { //for directories append incremented number after underscore $ i = 1 ; while ( file_exists ( $ newFileName = $ basePath . DIRECTORY_SEPARATOR . $ oldFileName . "_" . $ i ) ) { $ i ++ ; } } else { //for files insert incremented number between filename and extension $ exp = explode ( "." , $ oldFileName ) ; $ extension = array_pop ( $ exp ) ; $ name = implode ( "." , $ exp ) ; $ i = 1 ; while ( file_exists ( $ newFileName = $ basePath . DIRECTORY_SEPARATOR . $ name . "." . $ i . "." . $ extension ) ) { $ i ++ ; } } return $ newFileName ; }
If a previous file exists, create a new path, numerically incrementing a number in the string to avoid conflicts.

@param  string $path
@return string
If a previous file exists create a new path numerically incrementing a number in the string to avoid conflicts .