public function getNewFileName($targetFilename)
    {

        // load the file information
        $fileInfo = pathinfo($targetFilename);

        // query whether or not, the file exists
        if ($this->getFilesystemAdapter()->isFile($targetFilename)) {
            // initialize the incex and the basename
            $index = 1;
            $baseName = $fileInfo['filename'] . '.' . $fileInfo['extension'];

            // prepare the new filename by raising the index
            while ($this->getFilesystemAdapter()->isFile($fileInfo['dirname'] . '/' . $baseName)) {
                $baseName = $fileInfo['filename'] . '_' . $index . '.' . $fileInfo['extension'];
                $index++;
            }

            // set the new filename
            $targetFilename = $baseName;
        } else {
            // if not, simply return the filename
            return $fileInfo['basename'];
        }

        // return the new filename
        return $targetFilename;
    }
public function getNewFileName($targetFilename)
    {

        // load the file information
        $fileInfo = pathinfo($targetFilename);

        // query whether or not, the file exists
        if ($this->getFilesystemAdapter()->isFile($targetFilename)) {
            // initialize the incex and the basename
            $index = 1;
            $baseName = $fileInfo['filename'] . '.' . $fileInfo['extension'];

            // prepare the new filename by raising the index
            while ($this->getFilesystemAdapter()->isFile($fileInfo['dirname'] . '/' . $baseName)) {
                $baseName = $fileInfo['filename'] . '_' . $index . '.' . $fileInfo['extension'];
                $index++;
            }

            // set the new filename
            $targetFilename = $baseName;
        } else {
            // if not, simply return the filename
            return $fileInfo['basename'];
        }

        // return the new filename
        return $targetFilename;
    }
public function getNewFileName ( $ targetFilename ) { // load the file information $ fileInfo = pathinfo ( $ targetFilename ) ; // query whether or not, the file exists if ( $ this -> getFilesystemAdapter ( ) -> isFile ( $ targetFilename ) ) { // initialize the incex and the basename $ index = 1 ; $ baseName = $ fileInfo [ 'filename' ] . '.' . $ fileInfo [ 'extension' ] ; // prepare the new filename by raising the index while ( $ this -> getFilesystemAdapter ( ) -> isFile ( $ fileInfo [ 'dirname' ] . '/' . $ baseName ) ) { $ baseName = $ fileInfo [ 'filename' ] . '_' . $ index . '.' . $ fileInfo [ 'extension' ] ; $ index ++ ; } // set the new filename $ targetFilename = $ baseName ; } else { // if not, simply return the filename return $ fileInfo [ 'basename' ] ; } // return the new filename return $ targetFilename ; }
Get new file name if the same is already exists.

@param string $targetFilename The name of the exisising files

@return string The new filename
Get new file name if the same is already exists .