I’m using curl to download different files (e.g .doc, .jpg, jpeg , docx etc) from a webmail so I would like to know how find this extension because the link that I’m using(e.g example.com/file=3838438) basically outputs the file content but there is no file extension specified in the link.
Share
You probably want the MIME types, not the extension (which is unreliable). The MIME type is a portable way to identify the file type. Examples are
image/jpegandtext/html.First, check whether that site tells you the mime type in the HTTP response. You want to look for the Content-Type header.
If that isn’t useful, you can use
finfo_fileorfinfo_bufferto guess mime types. These are available from PECL, or in PHP 5.3 and later.In older versions of PHP, you can use
mime_content_type.