|
Posted by Shelly on 07/10/05 07:32
"Mladen Gogala" <gogala@sbcglobal.net> wrote in message
news:pan.2005.07.10.04.10.02.166470@sbcglobal.net...
> On Sat, 09 Jul 2005 20:30:57 -0400, Shelly wrote:
>
>> I have the following test for uploading audio files:
>>
>> if (strncmp($_FILES['filename']['type'],"audio", 5)) {
>>
>> I can successfully upload a "*.mid" file, but it fails on a "*.mp3"
>> file. Since the "*.mp3" is an audio file, why does it fail?
>
> Because the "type" attribute of a file is provided by the browser and
> your browser doesn't know what is the type of the MP3 files. If you are
> using mozilla browser, it has Navigator->Helper Applications menu that can
> be used to define that. You should start doing things like this:
>
> list($name,$ext)=preg_split('/\./',$_FILES['filename']['name'],2);
>
> switch (strtolower($ext)) {
> case "txt":
> case "doc":
> case "rtf":
> print "Heureka, it's a document!\n";
> break;
> case "rtfm":
> print "Heureka, it's a useful instruction!\n"; break;
> case "wav":
> case "mid":
> case "aiff":
> case "ogg":
> case "mp3":
> print "Heureka, it's an audio file!\n"; break;
> default:
> print "Are you sure that it's a file?\n"; break;
> }
>
> That would eliminate the dependency on browser provided information. Of
> course, you can use explode instead of preg_split if you are not a perl
> aficionado, like me.
Thanks. I'm very surprised. The browser I am using is Internet Explorer.
When I used the file/open of an mp3 file in Internet Explorer it brought up
a skin and played it.
Shelly
>
> --
> http://www.mgogala.com
>
Navigation:
[Reply to this message]
|