php 获取 mime type 类型,fileinfo扩展
2014-10-22 11:33
295 查看
背景:
version < php-5.3 没有API能够查看文件的 mime_type, 故需要编译扩展 fileinfo 来扩展PHP的API(finfo_*系列函数)。php-5.3 以后将fileinfo 拉入的官方发行包中,将不存在此问题。
知识准备:
软件准备:
php: php-5.2.14
Fileinfo: Fileinfo-1.0.4.tgz
file: file-5.20.tar.gz
1、file 安装
2、Fileinfo扩展编译安装
3、验证
备注:
1、安装软件注意查看 ./configure --help 其中会指出库或头文件的依赖
2、扩展移植,查看依赖, 移植需要注意对:libmagic.so.1 的依赖
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.
为了检测文件的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.4.tgz cd Fileinfo-1.0.4/ /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类型Fileinfo等方法
- PHP Fileinfo获取文件MIME类型
- php 利用Fileinfo 获取文件MIME类型(finfo_open) 下载
- php5.4.31安装php_fileinfo扩展和php_intl扩展
- PHP扩展sockets和Fileinfo , 实现发送邮件
- ubuntu下安装和使用php的fileinfo扩展
- Linux php安装fileinfo扩展
- Lnmp php安装fileinfo扩展
- 编译安装php扩展fileinfo
- php 安装fileinfo扩展
- centos安装php缺失fileinfo.so扩展解决
- 获取文件图标,类型名称,属性 SHGetFileInfo
- ubantu16.04服务器错误提示没有安装php_fileinfo扩展
- php7.0 扩展fileinfo.so
- Linux下安装php的扩展文件fileinfo.so文件
- linux 安装 PHP fileinfo 扩展
- Centos 下PHP编译安装fileinfo扩展
- php5.4安装fileinfo扩展
- CentOs环境下给PHP7.0安装fileinfo扩展
- 【MoreWindows工作笔记4】 获取文件图标,类型名称,属性 SHGetFileInfo