【问题标题】:php - get file type from contentsphp - 从内容中获取文件类型
【发布时间】:2014-02-10 04:25:34
【问题描述】:

我正在寻找一个从文件内容中获取文件类型的函数。

即。

public function wideImage( $width, $height, $cropped, $file )
{
    $cacheForInMinues = 15;
    $cacheName = md5( $file . $width . $height . $cropped );
    if ( Cache::has( "images.{$cacheName}" ) )
    {
        $image = Cache::get( "images.{$cacheName}" );
        // get_file_type_from_contents( $image );
    }
    else
    {
        ....

问候

【问题讨论】:

    标签: php image mime-types


    【解决方案1】:

    你可以使用fileinfo;

    <?php
    function get_file_type_from_contents($image) {
        $finfo = new finfo;
        $fileInfo = $finfo->file($image, FILEINFO_MIME);
        return $fileInfo;
    }
    

    【讨论】:

    • 警告此功能已被弃用,因为 PECL 扩展 Fileinfo 以更简洁的方式提供了相同的功能(以及更多功能)。
    • 谢谢@Dragon,我忘记了
    【解决方案2】:

    您应该阅读内容的标题。 看看这个:http://www.mikekunz.com/image_file_header.html

    但我不知道是否有一个已经制作的功能可以做到这一点。

    【讨论】:

      猜你喜欢
      • 2013-07-12
      • 2010-11-16
      • 2011-03-02
      • 2014-05-31
      • 2012-06-20
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 2011-07-29
      相关资源
      最近更新 更多