Background info:
- I'm collecting some URLs dynamically from various sources online.
- I would like to get the URL's content if it's an HTML page or an image.
- I do not want to load large files (like a download zip, pdf or others) - just to realize that the target is not interesting for me.
Is there a way I can check the response type/format with PHP before actually fetching the content? (to avoid wasting my own and the target servers resources and bandwidth)
(I found get_headers()
in the PHP doc, but it is unclear to me, if the function actually fetches the entire content and returns the headers, or somehow only gets the headers from the server, without downloading the content first. I also found solutions to get headers with CURL and fsocketopen, but the question remains, if I can do it without loading actual content)