【问题标题】:Call to undefined function exif_imagetype()调用未定义函数 exif_imagetype()
【发布时间】:2013-04-17 01:01:28
【问题描述】:

我正在尝试为image-types 获取Mime-Type,如下所示:

if(!empty($_FILES['uploadfile']['name']) && $_FILES['uploadfile']['error'] == 0){    

    $file = $_FILES['uploadfile']['tmp_name'];
    $file_type = image_type_to_mime_type(exif_imagetype($file));

    switch($file_type){

        // Codes Here

    }

}

但它总是给出错误Call to undefined function exif_imagetype()。我在这里做错了什么?

【问题讨论】:

  • @phpNoOb 我在那里尝试过作为答案,但仍然是同样的错误。

标签: php image file-upload upload mime-types


【解决方案1】:

php.ini 中启用以下扩展并重新启动您的服务器。

扩展=php_mbstring.dll
extension=php_exif.dll

然后检查phpinfo()是否设置为开/关

【讨论】:

  • --enable-exif #For Linux
  • 对于 linux 将是 extension=exif.so。我在 php 文档中找不到 --enable-exif 选项。
  • 如果你从源代码编译 PHP。当您 --configure / 时,您可以运行 --enable-exif。它@BakaKuna
【解决方案2】:

我认为问题在于 PHP 配置和/或版本,例如,就我而言:

我们知道exif_imagetype() 获取文件路径或资源并返回一个常量,如 IMAGETYPE_GIF image_type_to_mime_type() 采用该常量值并返回字符串 'image/gif''image/jpeg' 等。 这不起作用(缺少函数 exif_imagetype),所以我发现image_type_to_mime_type() 也可以将整数 1、2、3、17 等作为输入, 所以使用getimagesize解决了这个问题,它返回一个整数值作为mime类型:

function get_image_type ( $filename ) {
    $img = getimagesize( $filename );
    if ( !empty( $img[2] ) )
        return image_type_to_mime_type( $img[2] );
return false;
}

echo get_image_type( 'my_ugly_file.bmp' );
// returns image/x-ms-bmp
echo get_image_type( 'path/pics/boobs.jpg' );
// returns image/jpeg

【讨论】:

    【解决方案3】:

    将此添加到您的代码中,以便我们知道您拥有哪个版本的 php,因为此功能仅受(PHP 版本 4 >= 4.3.0,PHP 5)支持。

    <?php 
        phpinfo(); 
    ?> 
    

    可能没有安装,你可以添加这部分代码来确保它是:

    <?php
    if (function_exists('exif_imagetype')) {
        echo "This function is installed";
    } else {
        echo "It is not";
    }
    ?>
    

    【讨论】:

    • 我在PHP Version 5.2.9
    • @Kishor Subedi,检查我的编辑,顺便说一句,你是在 windows 下还是 linux 下?
    猜你喜欢
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 2014-04-24
    • 2016-10-11
    • 2018-01-31
    • 2013-09-11
    相关资源
    最近更新 更多