Reputation: 389
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.
Upvotes: 2
Views: 555
Reputation: 98519
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_headers
function) and then reading the returned Content-Type
header.
Make sure to fail gracefully if the remote end is inaccessible.
Upvotes: 3
Reputation: 33
Googling a little found me this:
http://php.net/manual/en/function.getallheaders.php
You then can read the "content-type" header entry.
Upvotes: 2