public function getUniqueFileOrFolderPath($path)
    {
        if ($path === '') {
            throw new \InvalidArgumentException('The first parameter $path must not be empty.', 1476054696353);
        }

        $pathInformation = pathinfo($path);
        $fileNameWithoutExtension = $pathInformation['filename'];
        if ($pathInformation['dirname'] !== '.') {
            $absoluteDirectoryWithTrailingSlash = $this->getUploadFolderPath() . $pathInformation['dirname'] . '/';
        } else {
            $absoluteDirectoryWithTrailingSlash = $this->getUploadFolderPath();
        }

        $extension = isset($pathInformation['extension']) ? ('.' . $pathInformation['extension']) : '';

        $suffixCounter = 0;
        do {
            $suffix = ($suffixCounter > 0) ? ('-' . $suffixCounter) : '';
            $newPath = $absoluteDirectoryWithTrailingSlash . $fileNameWithoutExtension . $suffix . $extension;
            $suffixCounter++;
        } while (is_file($newPath));

        return $newPath;
    }
public function getUniqueFileOrFolderPath($path)
    {
        if ($path === '') {
            throw new \InvalidArgumentException('The first parameter $path must not be empty.', 1476054696353);
        }

        $pathInformation = pathinfo($path);
        $fileNameWithoutExtension = $pathInformation['filename'];
        if ($pathInformation['dirname'] !== '.') {
            $absoluteDirectoryWithTrailingSlash = $this->getUploadFolderPath() . $pathInformation['dirname'] . '/';
        } else {
            $absoluteDirectoryWithTrailingSlash = $this->getUploadFolderPath();
        }

        $extension = isset($pathInformation['extension']) ? ('.' . $pathInformation['extension']) : '';

        $suffixCounter = 0;
        do {
            $suffix = ($suffixCounter > 0) ? ('-' . $suffixCounter) : '';
            $newPath = $absoluteDirectoryWithTrailingSlash . $fileNameWithoutExtension . $suffix . $extension;
            $suffixCounter++;
        } while (is_file($newPath));

        return $newPath;
    }
public function getUniqueFileOrFolderPath ( $ path ) { if ( $ path === '' ) { throw new \ InvalidArgumentException ( 'The first parameter $path must not be empty.' , 1476054696353 ) ; } $ pathInformation = pathinfo ( $ path ) ; $ fileNameWithoutExtension = $ pathInformation [ 'filename' ] ; if ( $ pathInformation [ 'dirname' ] !== '.' ) { $ absoluteDirectoryWithTrailingSlash = $ this -> getUploadFolderPath ( ) . $ pathInformation [ 'dirname' ] . '/' ; } else { $ absoluteDirectoryWithTrailingSlash = $ this -> getUploadFolderPath ( ) ; } $ extension = isset ( $ pathInformation [ 'extension' ] ) ? ( '.' . $ pathInformation [ 'extension' ] ) : '' ; $ suffixCounter = 0 ; do { $ suffix = ( $ suffixCounter > 0 ) ? ( '-' . $ suffixCounter ) : '' ; $ newPath = $ absoluteDirectoryWithTrailingSlash . $ fileNameWithoutExtension . $ suffix . $ extension ; $ suffixCounter ++ ; } while ( is_file ( $ newPath ) ) ; return $ newPath ; }
Returns a unique absolute path of a file or folder.

@param string $path the path of a file or folder relative to the calling extension's upload directory,
must not be empty

@return string the unique absolute path of a file or folder

@throws \InvalidArgumentException
Returns a unique absolute path of a file or folder .