我想将一些谷歌驱动器文件的 url 与 mime 类型一起保存到数据库中。在 JavaScript(最好)或 PHP 中有什么方法可以检查 url 并找出它是什么类型的文件? audio/mp3
, video/mp4
等?
这是文件的语法,但不幸的是,无法根据 url 判断它是哪种文件:https://drive.google.com/uc?export=download&id=0B_Tg8P0D8mAYUHlrX3NWRmwwOGc
感谢线索!
最佳答案
在 PHP 中,您可以使用带有 CURLINFO_CONTENT_TYPE
标志的 cURLs curl_getinfo
函数
<?php
// the request
$ch = curl_init($documentURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
// get the content type
echo curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
?>
您的输出将按照 text/html 行; charset=ISO-8859-1
,您可以展开
以仅获取 MIME 类型:
<?php
$mime = explode(";", curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
echo $mime[0];
?>
关于javascript - 有没有办法从 JS 或 PHP 中的 Google Drive 链接中找出 mime 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45515966/