So I’m going to transfer a file from a remote server to my server but before I transfer it I want to know what sort of file it is. If it’s an HTML file I’ll deal with it in a certain way, if it’s a PDF file I’ll deal with it in a different way, and if, for instance, it’s an exe file, I don’t want to transfer it at all.
All I’ve got to go on is a URL. Now if that URL is explicit (i.e. http://example.com/file.pdf) it’s not a problem, I can just check the file extension and we’re sorted. However, I might only be given a URL such as http://example.com and it could be anything.
Is it possible to check (with PHP) what type of file it is before I download it?
Edit: I will be using cURL to transfer the file, but I believe that curl_getinfo can only be called after the file has been transferred?
Try using PHP get_headers function, e.g.: