Reply to Re: Audio files - *.mp3

Your name:

Reply:


Posted by Mladen Gogala on 07/10/05 07:10

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.

--
http://www.mgogala.com

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация