How can I detect the content type of a link?
Users can upload links into thee web. And I’d need to save the link type (a video, a image…) in the DB (mysql).
I’ve found one answer (using the HTTP HEAD) with Java:
Selenium 2: Detect content type of link destinations
. However I’m using PHP.
Thanks.
That solution applies, in the abstract, to PHP as well.
The way you detect a link target’s content type is by performing an HTTP HEAD request (such as with the curl extension for PHP, or the
get_headersfunction) and then reading the returnedContent-Typeheader.Make sure to fail gracefully if the remote end is inaccessible.