protected function dirname($path)
    {
        if (is_file($path)) {
            return dirname($path);
        }

        if (is_dir($path)) {
            return rtrim($path, '/');
        }

        // no known file/dir, start making assumptions

        // ends in / = dir
        if (mb_substr($path, -1) === '/') {
            return rtrim($path, '/');
        }

        // has a dot in the name, likely a file
        if (preg_match('/.*\..*$/', basename($path)) !== 0) {
            return dirname($path);
        }

        // you're on your own here!
        return $path;
    }
protected function dirname($path)
    {
        if (is_file($path)) {
            return dirname($path);
        }

        if (is_dir($path)) {
            return rtrim($path, '/');
        }

        // no known file/dir, start making assumptions

        // ends in / = dir
        if (mb_substr($path, -1) === '/') {
            return rtrim($path, '/');
        }

        // has a dot in the name, likely a file
        if (preg_match('/.*\..*$/', basename($path)) !== 0) {
            return dirname($path);
        }

        // you're on your own here!
        return $path;
    }
protected function dirname ( $ path ) { if ( is_file ( $ path ) ) { return dirname ( $ path ) ; } if ( is_dir ( $ path ) ) { return rtrim ( $ path , '/' ) ; } // no known file/dir, start making assumptions // ends in / = dir if ( mb_substr ( $ path , - 1 ) === '/' ) { return rtrim ( $ path , '/' ) ; } // has a dot in the name, likely a file if ( preg_match ( '/.*\..*$/' , basename ( $ path ) ) !== 0 ) { return dirname ( $ path ) ; } // you're on your own here! return $ path ; }
Attempt to get the directory name from a path.

@param string $path

@return string
Attempt to get the directory name from a path .