MIME::bufferGetType PHP Method

bufferGetType() public method

public bufferGetType ( $buf, $filename = NULL )
    public function bufferGetType($buf, $filename = NULL)
    {
        if ($filename) {
            $filename = basename($filename);
        }
        if ($filename) {
            $r = $this->bufMagic($buf, 80);
            if ($r) {
                return $r;
            }
            $r = $this->literal($filename);
            if ($r) {
                return $r;
            }
            $r = $this->suffix($filename);
            if ($r) {
                return $r;
            }
            $r = $this->glob($filename);
            if ($r) {
                return $r;
            }
            $is_binary = $this->bufGuessBinary($buf);
            /*
             * Checking all magic signatures is a very expensive operation.
             * We trade off some accuracy for faster text/plain recognition.
             */
            if ($is_binary) {
                $r = $this->bufMagic($buf, 0, 79);
                if ($r) {
                    return $r;
                }
            }
        } else {
            $is_binary = $this->bufGuessBinary($buf);
            if ($is_binary) {
                $r = $this->bufMagic($buf);
            } else {
                $r = $this->bufMagic($buf, 80);
            }
            if ($r) {
                return $r;
            }
        }
        return $is_binary ? 'application/octet-stream' : 'text/plain';
    }

Usage Example

Exemplo n.º 1
0
 public function getMimeType()
 {
     if (!$this->object) {
         return NULL;
     }
     if (!$this->mime_type) {
         $mime = new MIME(Config::MIME_CACHE_PATH);
         $this->mime_type = $mime->bufferGetType($this->object->data, $this->getName());
     }
     return $this->mime_type;
 }