PHP FileInfo open() 函数
finto_open() 函数可以创建一个新的 fileinfo 资源。
语法
resource finfo_open ([ int options [, stringarg ]] )
Object oriented style (constructor):
finfo
__construct ([ int options [, stringmagic_file ]] )
此函数可以打开一个魔术数据库,并在成功时返回其资源和魔术数据库资源,失败时返回false。
示例-面向对象风格
<?php
finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension
if(!finfo) {
echo "Opening fileinfo database failed";
exit();
}
/* get mime-type for a specific file */
filename = "/usr/local/something.txt";
echofinfo->file(filename);
/* close connection */finfo->close();
?>
实例 – 过程化样式
<?php
finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension
if(!finfo) {
echo "Opening fileinfo database failed";
exit();
}
/* get mime-type for a specific file */
filename = "/usr/local/something.txt";
echo finfo_file(finfo, filename);
/* close connection */
finfo_close(finfo);
?>