相关疑难解决方法(0)

为什么PHP中不推荐使用mime_content_type()?

我只是想知道为什么现在认为mime_content_type()被弃用了.

这种用于确定mime类型的方法比替换Fileinfo功能容易得多.

php deprecated mime-types

24
推荐指数
4
解决办法
3万
查看次数

在php中检测mime类型失败

我有以下PHP代码,显示上传文件的mime类型.

<?php

if ($_POST) {

    var_dump($_FILES);

    $finfo = new finfo(FILEINFO_MIME_TYPE);

    var_dump($finfo->file($_FILES['file']['tmp_name']));

} else{
    ?>
    <form method="POST" enctype="multipart/form-data"><input name="file" type="file"><input name="submit" value="send" type="submit"/></form>
    <?php
}
Run Code Online (Sandbox Code Playgroud)

使用此脚本上传somefile.csv的结果如下.

array (size=1)
    'file' =>
    array (size=5)
        'name' => string 'somefile.csv' (length=12)
        'type' => string 'text/csv' (length=8)
        'tmp_name' => string '/tmp/phpKiwqtu' (length=14)
        'error' => int 0
        'size' => int 3561
string 'text/x-fortran' (length=14)
Run Code Online (Sandbox Code Playgroud)

所以mime类型当然应该是text/csv.但我使用的框架(Symfony 1.4)使用fileinfo的方法.

此外,我进一步测试了看起来命令(在Ubuntu上)file --mime-type somefile.csv返回somefile.csv: text/x-fortran并且命令mimetype somefile.csv返回somefile.csv: text/csv.somefile.csv是用MSOffice创建的(我不知道这是否重要).显然mimetype使用了一些很棒的mime数据库(http://freedesktop.org/wiki/Software/shared-mime-info),而file没有.

  1. PHP使用 …

php symfony-1.4 mime-types

4
推荐指数
1
解决办法
1602
查看次数

标签 统计

mime-types ×2

php ×2

deprecated ×1

symfony-1.4 ×1