src/Utilities/Miscellaneous.php
public static function getUniqueFileName($originalFileName, $objectId = 0)
    {
        $withoutExtension = self::getFileNameWithoutExtension($originalFileName);
        $extension = self::getFileExtension($originalFileName, true);

        /*
         * Let's clear name of file
         *
         * Attention.
         * The name without extension may be cleared / urlized only to avoid incorrect name by replacing "." with "-".
         */
        $withoutExtension = Urlizer::urlize($withoutExtension);

        // Now I have to complete the template used to build / generate unique name
        $template = '%s-%s.%s'; // [file's name]-[unique key].[file's extension]

        // Add some uniqueness
        $unique = self::getUniqueString(mt_rand());

        // Finally build and return the unique name
        if ($objectId > 0) {
            $template = '%s-%s-%s.%s'; // [file's name]-[unique key]-[object ID].[file's extension]

            return sprintf($template, $withoutExtension, $unique, $objectId, $extension);
        }

        return sprintf($template, $withoutExtension, $unique, $extension);
    }
public static function getUniqueFileName($originalFileName, $objectId = 0)
    {
        $withoutExtension = self::getFileNameWithoutExtension($originalFileName);
        $extension = self::getFileExtension($originalFileName, true);

        /*
         * Let's clear name of file
         *
         * Attention.
         * The name without extension may be cleared / urlized only to avoid incorrect name by replacing "." with "-".
         */
        $withoutExtension = Urlizer::urlize($withoutExtension);

        // Now I have to complete the template used to build / generate unique name
        $template = '%s-%s.%s'; // [file's name]-[unique key].[file's extension]

        // Add some uniqueness
        $unique = self::getUniqueString(mt_rand());

        // Finally build and return the unique name
        if ($objectId > 0) {
            $template = '%s-%s-%s.%s'; // [file's name]-[unique key]-[object ID].[file's extension]

            return sprintf($template, $withoutExtension, $unique, $objectId, $extension);
        }

        return sprintf($template, $withoutExtension, $unique, $extension);
    }
public static function getUniqueFileName ( $ originalFileName , $ objectId = 0 ) { $ withoutExtension = self :: getFileNameWithoutExtension ( $ originalFileName ) ; $ extension = self :: getFileExtension ( $ originalFileName , true ) ; /*
         * Let's clear name of file
         *
         * Attention.
         * The name without extension may be cleared / urlized only to avoid incorrect name by replacing "." with "-".
         */ $ withoutExtension = Urlizer :: urlize ( $ withoutExtension ) ; // Now I have to complete the template used to build / generate unique name $ template = '%s-%s.%s' ; // [file's name]-[unique key].[file's extension] // Add some uniqueness $ unique = self :: getUniqueString ( mt_rand ( ) ) ; // Finally build and return the unique name if ( $ objectId > 0 ) { $ template = '%s-%s-%s.%s' ; // [file's name]-[unique key]-[object ID].[file's extension] return sprintf ( $ template , $ withoutExtension , $ unique , $ objectId , $ extension ) ; } return sprintf ( $ template , $ withoutExtension , $ unique , $ extension ) ; }
Returns unique name for file based on given original name

@param string $originalFileName Original name of the file
@param int    $objectId         (optional) Object ID, the ID of database's row. May be included into the
generated / unique name.
@return string
Returns unique name for file based on given original name