Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Getting the content-type

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Getting the content-type

Postby Icarus » Thu Oct 24, 2002 9:36 am

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 ?
User avatar
Icarus
New php-forum User
New php-forum User
 
Posts: 7
Joined: Thu Oct 24, 2002 9:32 am
Location: Amsterdam, NL

Postby Jay » Thu Oct 24, 2002 1:02 pm

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!
Jay
 

Postby Icarus » Thu Oct 24, 2002 11:30 pm

If you do :

Code: Select all
[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.
User avatar
Icarus
New php-forum User
New php-forum User
 
Posts: 7
Joined: Thu Oct 24, 2002 9:32 am
Location: Amsterdam, NL

Postby DutchBen » Fri Oct 25, 2002 10:26 am

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
DutchBen
New php-forum User
New php-forum User
 
Posts: 36
Joined: Thu Oct 24, 2002 10:28 am
Location: Amsterdam


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.