php 获取 mime type 类型,fileinfo扩展
背景:
version < php-5.3 没有API能够查看文件的 mime_type, 故需要编译扩展 fileinfo 来扩展PHP的API(finfo_*系列函数)。php-5.3 以后将fileinfo 拉入的官方发行包中,将不存在此问题。
知识准备:
MIME type的缩写为(Multipurpose Internet Mail Extensions)代表互联网媒体类型(Internet media type),MIME使用一个简单的字符串组成,最初是为了标识邮件Email附件的类型,在html文件中可以使用content-type属性表示,描述了文件类型的互联网标准。
MIME类型能包含视频、图像、文本、音频、应用程序等数据。为了检测文件的MIME类型,必须配置告知magic文件的地址(如果不指定,默认使用apache 的magic地址)
mime_magic extensionYou must compile PHP with the configure switch --with-mime-magic to get support for mime-type functions. The extension needs a copy of the simplified magic file that is distributed with the Apache httpd. 所以php 在apache mod 模式下的 $_FILE['img']['type'] 字段数据依赖于Apache 发布的相应版本的 magic file.exif extensionWith the exif extension you are able to work with image meta data. For example, you may use exif functions to read meta data of pictures taken from digital cameras by working with information stored in the headers of the JPEG and TIFF images.
软件准备:
php: php-5.2.14
Fileinfo: Fileinfo-1.0.4.tgz
file: file-5.20.tar.gz
1、file 安装
wget ftp://ftp.astron.com/pub/file/file-5.15.tar.gz
tar zxf file-5.20.tar.gz
cd file-5.20/
./configure --prefix=/usr/local/services/file-5.20
make
make install
2、Fileinfo扩展编译安装
wget http://pecl.php.net/get/Fileinfo-1.0.4.tgz
tar zxf Fileinfo-1.0..tgz
cd Fileinfo-1.0./
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-fileinfo=/usr/local/services/file-5.20/
make
#拷贝fileinfo.so 到php.ini 中定义的 extension_dir
cp fileinfo.so /usr/local/php/extensions/ #修改php.ini
echo "extension=fileinfo.so" >> /usr/local/php/lib/php.ini
3、验证
php -m | grep fileinfo
fileinfo
备注:
1、安装软件注意查看 ./configure --help 其中会指出库或头文件的依赖
2、扩展移植,查看依赖, 移植需要注意对:libmagic.so.1 的依赖
ldd /usr/local/php/extensions/fileinfo.so
linux-vdso.so.1 => (0x00007fff9b7ff000)
libmagic.so.1 => /usr/local/lib/libmagic.so.1 (0x00007f8493582000)
libc.so.6 => /lib64/libc.so.6 (0x00007f8493342000)
libz.so.1 => /lib64/libz.so.1 (0x00007f849322d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f84937a4000)
php 获取 mime type 类型,fileinfo扩展的更多相关文章
- mime type 类型名字应该用多长的字段?
在使用 FastAdmin 时有 mimetype 字段使用了 50 长度,有小伙伴反应,不够. 在 Linux 服务器上时 xlsx 文件的 mimetype 是 application/vnd. ...
- 学习PHP中Fileinfo扩展的使用
今天来学习的这个扩展其实现在也已经是标配的一个扩展了,为什么呢?因为 Laravel 框架在安装的时候它就是必须的一个扩展,没有打开它的话,连 Laravel 框架都是无法使用的. Fileinfo ...
- MIME Type介绍 Content-Type 各种定义
多用途互联网邮件扩展(MIME,Multipurpose Internet Mail Extensions)是一个互联网标准,它扩展了电子邮件标准,使其能够支持非ASCII字符.二进制格式附件等多种格 ...
- File upload - MIME type
Your goal is to hack this photo galery by uploading PHP code.Retrieve the validation password in the ...
- php获取文件mime类型Fileinfo等方法
前几天写到使用wordpress xmlrpc api远程发布文章,如果本地服务器的文章库里某一篇待发表的wordpress文章包含图片文件时,就会使用到WordPress上传文件的API metaW ...
- [笔记] C# 如何获取文件的 MIME Type
MIME Type 为何物: MIME 参考手册 svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types 常规方式 对于有文件后 ...
- js 获取input type="file" 选择的文件大小、文件名称、上次修改时间、类型等信息
文件名的传递 ---全路径获取 $('#file').change(function(){ $('#em').text($('#file').val()); }); 文件名的传递 ---只获取文件名 ...
- C#获取文件的Content-Type(MIME Type)的方法
使用静态类MimeMapping(需要.NET Framework 4.5及以后的支持) string fileName = "D:\myfile.txt"; var conten ...
- windows环境开启PHP fileinfo扩展
fileinfo作用:本模块中的函数通过在文件的给定位置查找特定的 魔术 字节序列 来猜测文件的内容类型以及编码(通俗来讲就是获取文件的MIME信息) 开启PHP fileinfo扩展的方法: 1.下 ...
随机推荐
- How to add the ApplicationPoolIdentity to a SQL Server Login
The ApplicationPoolIdentity is a virtual account in Windows that is dynamically generated when the a ...
- is7.5和iis8文件上传大小限制30M修改方法
C:\Windows\System32\inetsrv\config\schema\ 下的IIS_schema.xml文件,但是考虑到安全等问题,而且这个文件默认是只读的,所以不建议直接修改这个配置文 ...
- js常用校验
//验证金钱数字obj.regexMoney = function (money) { var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)| ...
- MySQL5.6的4个自带库详解
MySQL5.6的4个自带库详解 1.information_schema详细介绍: information_schema数据库是MySQL自带的,它提供了访问数据库元数据的方式.什么是元数据呢?元数 ...
- POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 Description After going through the receipts from your car trip ...
- hive拉链表
前言 本文将会谈一谈在数据仓库中拉链表相关的内容,包括它的原理.设计.以及在我们大数据场景下的实现方式. 全文由下面几个部分组成:先分享一下拉链表的用途.什么是拉链表.通过一些小的使用场景来对拉链表做 ...
- 安装MAC的ReactNative环境
brew install node brew install watchman npm config set registry https://registry.npm.taobao.org --gl ...
- en-zh(社会问题)social problems
The world's richest man, Amazon founder Jeff Bezos, and his wife MacKenzie have agreed a record-brea ...
- [ovs][libvirt][virtio][qemu] vhost user client 排障
ovs-dpdk + qemu 使用vhostuserclient通信,连路不通,libvirt报错如下: -- ::: starting up libvirt version: , package: ...
- 状压dp的另一种形式
做的那么多都是一些比较怎么说呢,都是在数网格一类的题目之中,这些题目有些有点固定的套路,而一些需要状态压缩的题目呢,则么是真正对状态转移的考验. 这道题呢,被彻底打脸了,以后一定要任性一点一道题做不出 ...