檢測檔案的 MIME 型別

mime_content_type

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

mime_content_type檢測檔案的 MIME 型別

說明

mime_content_type(string $filename): string

返回通過使用 magic.mime 檢測到的檔案 MIME 型別。

參數

filename

要檢測的檔名。

返回值

返回檔案的 MIME 內容型別,例如 text/plainapplication/octet-stream。 或者在失敗時返回 false

錯誤/異常

失敗時拋出E_WARNING警告。

範例

示例 #1 mime_content_type() 示例

<?php
echo mime_content_type('php.gif') . "\n";
echo 
mime_content_type('test.php');
?>

以上例程會輸出:

image/gif
text/plain

參見

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *