0

So, I've got to download a file to do a verification, I must check if the downloaded file is an XML or an ZIP.

I have the following code:

$url = $return->DocXMLLink; //link to download the file
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);

$response = curl_exec($ch);
//by here I may get the file extension and do something

Thanks in advance

Raphael Andres
  • 77
  • 2
  • 14
  • Correct me if I am wrong but you can probably extract the file extension from the `$return->DocXMLLink` string. See https://stackoverflow.com/q/173868/2191572 for more info. – MonkeyZeus Dec 05 '18 at 18:43
  • No, it returns a download link, but unfortunately doesn't has the extension – Raphael Andres Dec 05 '18 at 18:44
  • If you do not have an extension available to you then you can get the [headers using CURL](https://stackoverflow.com/q/9183178/2191572). If the file information is not in the headers then will need to save the file to your disk and use [`mime_content_type()`](http://php.net/manual/en/function.mime-content-type.php) – MonkeyZeus Dec 05 '18 at 18:48
  • 1
    It worked with the headers. Thanks :) – Raphael Andres Dec 06 '18 at 16:08
  • Nice, you're welcome – MonkeyZeus Dec 06 '18 at 16:22

0 Answers0