PHPDaemon\Utils\MIME::get PHP Méthode

get() public static méthode

Returns MIME type of the given file
public static get ( string $path ) : string
$path string Path
Résultat string MIME type
    public static function get($path)
    {
        $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
        if (!isset(self::$fileTypes[$ext])) {
            return false;
        }
        return self::$fileTypes[$ext];
    }

Usage Example

Exemple #1
0
 /**
  * Output whole contents of file
  * @param  string $path Path
  * @param  callable $cb Callback
  * @param  integer $pri Priority
  * @return boolean        Success
  */
 public function sendfile($path, $cb, $pri = EIO_PRI_DEFAULT)
 {
     if ($this->state === self::STATE_FINISHED) {
         return false;
     }
     try {
         $this->header('Content-Type: ' . MIME::get($path));
     } catch (RequestHeadersAlreadySent $e) {
     }
     if ($this->upstream->checkSendfileCap()) {
         FileSystem::sendfile($this->upstream, $path, $cb, function ($file, $length, $handler) {
             try {
                 $this->header('Content-Length: ' . $length);
             } catch (RequestHeadersAlreadySent $e) {
             }
             $this->ensureSentHeaders();
             $this->upstream->onWriteOnce(function ($conn) use($handler, $file) {
                 $handler($file);
             });
             return true;
         }, 0, null, $pri);
         return true;
     }
     $first = true;
     FileSystem::readfileChunked($path, $cb, function ($file, $chunk) use(&$first) {
         // readed chunk
         if ($this->upstream->isFreed()) {
             return false;
         }
         if ($first) {
             try {
                 $this->header('Content-Length: ' . $file->stat['size']);
             } catch (RequestHeadersAlreadySent $e) {
             }
             $first = false;
         }
         $this->out($chunk);
         return true;
     });
     return true;
 }
All Usage Examples Of PHPDaemon\Utils\MIME::get
MIME