Haridarshan Haridarshan - 1 month ago 23
PHP Question

PHP Mime Type for apk files

Why PHP method

$mime = mime_content_type($filename);
gives
mime-type = application/zip
for apk files?? I've defined apk mimetype in htaccess

.htaccess

<IfModule mod_mime.c>
AddType application/vnd.android.package-archive apk
AddType application/apk apk
AddType application/java-archive jar
</Ifmodule>

<FilesMatch \.apk$>
SetHandler application/vnd.android.package-archive
</FilesMatch>


I've tried all the solutions provided below but still none of them solved the problem. Need help regarding this.

Answer

That's because mime_content_type is not affected by .htaccess. However, the documentation specifies that you can set magic.mime file:

string mime_content_type ( string $filename )

Returns the MIME content type for a file as determined by using information from the magic.mime file.

There is also finfo_open (PECL) function that has $magic_file as a parameter.