Getting the content-type



Hi All,

I was just wondering ....
Is there a way to get the content-type of a remote file

lets say

Or does anybody know a code snippet that does this ?
You can read it using the file system functions, but you'll only get the HTTP version of it. So you can't read a PHP file for instance, as you're only going to get the output and not the source. The same for any script file!
If you do :

[maurits@shadow maurits]$ telnet localhost 80
Connected to localhost.localdomain (
Escape character is '^]'.
HEAD /paperclip.gif HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 25 Oct 2002 07:31:58 GMT
Server: Apache-Server/1.3.26 PHP/4.2.3
Last-Modified: Wed, 24 Jul 2002 14:45:04 GMT
ETag: "28884-49-3d3ebd70"
Accept-Ranges: bytes
Content-Length: 73
Connection: close
Content-Type: image/gif

Connection closed by foreign host.

All I want is the Content-Type of the remote file.
Header information is stored in the variable $http_reponse_header variable for files opened with fopen.

file_get_wrapper_data() can also be used to read the response header

Check for details