PHP has a function call mime_content_type (string $filename) that detect mime type (content type) of a particular file. This function is extremely useful when we try to download a file from an online URL or we don’t know exactly what extension/mime type of the file is.
According to a question from Greg Newman in PHP Download Image Or File From URL article:
What can one do when the $file_url is not fully qualified and does not directly point to a file.zip but rather points to a page that itself forces download of a file.zip.
In this scenario, he try to download a file from an external URL but the file name is not specified. It’s generated on the server and forces download. Therefore, we need to determine its mime type by using mime_content_type PHP function then rename that file to a corresponding extension.
PHP Function Detect Mime Type Of A File
<?php string mime_content_type ( string $filename ) ?> |