Call to undefined function exif_imagetype()

后端 未结 3 1972
悲哀的现实
悲哀的现实 2020-12-18 21:49

I am trying to get Mime-Type for image-types as follow:

if(!empty($_FILES[\'uploadfile\'][\'name\']) && $_FILES[\'uploadfil         


        
相关标签:
3条回答
  • 2020-12-18 22:03

    Add this to your code so as we could know which version of php you do have because this function is only supported by (PHP version 4 >= 4.3.0, PHP 5).

    <?php 
        phpinfo(); 
    ?> 
    

    It may be not installed, you can add this part of code to make sure it is :

    <?php
    if (function_exists('exif_imagetype')) {
        echo "This function is installed";
    } else {
        echo "It is not";
    }
    ?>
    
    0 讨论(0)
  • 2020-12-18 22:09

    Enable the following extensions in php.ini and restart your server.

    extension=php_mbstring.dll
    extension=php_exif.dll

    Then check phpinfo() to see if it is set to on/off

    0 讨论(0)
  • 2020-12-18 22:13

    I think the problem is PHP config and/or version, for example, in my case:

    We know exif_imagetype() takes a file path or resource and returns a constant like IMAGETYPE_GIF and image_type_to_mime_type() takes that constant value and returns a string 'image/gif', 'image/jpeg', etc. This didn't work (missing function exif_imagetype), so I've found that image_type_to_mime_type() can also take an integer 1, 2, 3, 17, etc. as input, so solved the problem using getimagesize, which returns an integer value as mime type:

    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
    
    0 讨论(0)
提交回复
热议问题