PHP获取远程文件MIME类型 [英] PHP get remote file mime-type

查看:587
本文介绍了PHP获取远程文件MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,检查远程文件mime类型的最快方法是什么...我正在考虑从第一个字节中读取一些内容,也许还有更多...我花了一些时间来思考如何使事情变得正确,但无济于事我的想法...我必须检查远程文件是否为mp3,但必须快速检查...

Hey what is the fastest way to check remote file mime-type... Im thinking about reading some from the first bytes, and maybe more... I spend some hours to think how to make the things right, but nothing on my mind... I must check IF the remote file is mp3, but it must be fastcheck...

推荐答案

PHP curl_getinfo()

PHP curl_getinfo()

<?php
    # the request
    $ch = curl_init('http://www.google.com');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);

    # get the content type
    echo curl_getinfo($ch, CURLINFO_CONTENT_TYPE);

    # output
    // text/html; charset=ISO-8859-1
?>

输出

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 09 Apr 2010 20:35:12 GMT
Expires: Sun, 09 May 2010 20:35:12 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219

要真正确认文件是否包含实际的MP3数据或任何其他媒体格式,我使用 getID3().

To actually confirm if the file contains actual MP3 data or any other media format, I use getID3().

这篇关于PHP获取远程文件MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆