Forum Moderators: coopster

Message Too Old, No Replies

Getting the true file extension, or mime type of a remote file

         

formasfunction

3:38 pm on Jan 17, 2008 (gmt 0)

10+ Year Member



I'm using get_headers (in PHP 5) to grab the mime-type of some files on other servers and I'm running into trouble with m4a files and servers that have the mime-type for them set as text/html. I'd like an alternative way to get the mime-type, without actually downloading the file (that's why I like get_headers). I was curious if there was a way to get the file extension of a file through php. I can't just extract it from the URL because some of them are being served without a visible file extension in the URL. Any ideas?

eelixduppy

5:46 pm on Jan 17, 2008 (gmt 0)




I'm running into trouble with m4a files and servers that have the mime-type for them set as text/html. I'd like an alternative way to get the mime-type

Wouldn't an alternate solution present you with the same problem?

formasfunction

5:54 pm on Jan 17, 2008 (gmt 0)

10+ Year Member



Well, I was hoping there might be a way to check the wrapper of the actual file rather than the header that the web server is sending.

PHP_Chimp

6:03 pm on Jan 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was going to say that there is no solution other than downloading and checking yourself for cases where the server is incorrectly identifying the mime type.

However you could look at downloading the first, say, 100 byes then examine those for the file markers, to see what type of file they actually are...although I guess that isnt really a realistic solution.

So is there another way to look at the problem -
why do you need the mime type is you already know its m4a?
are you only looking for files with that single mime type?
are you looking blindly for all files then picking m4a types, or do you know the location of those files and are just checking with the headers?

formasfunction

6:37 pm on Jan 17, 2008 (gmt 0)

10+ Year Member



--> why do you need the mime type is you already know its m4a?

m4a just happens to be the first one I ran into where my test cases didn't match up with what I already knew to be the file type. I'm running a test script on 300 or so DB entries before trying it on the larger DB.

--> are you only looking for files with that single mime type?

No. I have a DB of URLs pointing to various pages/files/media and I'm trying to separate them out by media type, where possible. The four large categories I'm using are htmt/text, images, audio, and video. I'm specifically interested in mp3 and m4a files because I want to play them through a flash player.

--> are you looking blindly for all files then picking m4a types, or do you know the location of those files and are just checking with the headers?

I have specific URLs in my DB but within those it's a blind sorting process. Right now I'm using a combination of grabbing the mime type using get_headers() and also grabbing the extension (if one is displayed) using pathinfo() which is better than one or the other but not as reliable or elegant as I'd like.

PHP_Chimp

8:23 pm on Jan 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Humm....well I still dont have any ideas about how to get the correct mime type when the server is giving the wrong one.

Are all of these files that you are having problems with on a single server?
You could separate out results from those offending servers and maybe have to check them manually, until a better solution is found.

Is it your server?
As you can add the m4a type so that the server will send the correct heading. Or if not yours then try talking to the server admin to get them to add the correct mime type headers for those files.

formasfunction

9:50 pm on Jan 17, 2008 (gmt 0)

10+ Year Member



--> Are all of these files that you are having problems with on a single server? Is it your server?

No, it seems like a lot of servers on the web aren't currently configured to handle m4a correctly. I suppose since it's a (relatively) new format hosting providers haven't gotten around to adding it to the list.