Getting the content-type

A

Anonymous

Guest
Hi All,

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

lets say http://someserver.com/file/somefile.ext

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 :

Code:
[maurits@shadow maurits]$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
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 php.net for details
 
Back
Top