By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

Audio type

P: n/a
I had a problem with uploading images in that some files did not have a type
of "image/something" from the
$_FILES['the_field_name']['type'] which I used for my verification.
Someone (THANK YOU) suggested using getimagesize() which has the third
element in the returned array being a number representing the image type.
That worked perfectly for me, enabling me to check that it was, indeed, an
image file that I had uploaded.

Now I ask if there is a similar function call for audio types. I want to be
able to verify that the file I upload is, indeed, an audio file. I would
like this function because I am reasoning that if the "type" obtained from
$_FILES['the_field_name']['type'] is not reliable for images, then it
probably isn't reliable for audio either.

Shelly
Jul 26 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Tue, 26 Jul 2005 16:34:01 GMT, "Shelly" <sh************@asap-consult.com>
wrote:
Now I ask if there is a similar function call for audio types. I want to be
able to verify that the file I upload is, indeed, an audio file. I would
like this function because I am reasoning that if the "type" obtained from
$_FILES['the_field_name']['type'] is not reliable for images, then it
probably isn't reliable for audio either.


There's the "mime magic" function:

http://uk2.php.net/mime_content_type

... which looks for magic numbers in the file to make a decent guess as to
what format a file is. Not foolproof, but generally reasonable.

The other alternative is presumably doing full parsing of the audio file
itself to look for known structures for the audio formats you're expecting.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 26 '05 #2

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:3k********************************@4ax.com...
On Tue, 26 Jul 2005 16:34:01 GMT, "Shelly"
<sh************@asap-consult.com>
wrote:
Now I ask if there is a similar function call for audio types. I want to
be
able to verify that the file I upload is, indeed, an audio file. I would
like this function because I am reasoning that if the "type" obtained from
$_FILES['the_field_name']['type'] is not reliable for images, then it
probably isn't reliable for audio either.


There's the "mime magic" function:

http://uk2.php.net/mime_content_type

... which looks for magic numbers in the file to make a decent guess as to
what format a file is. Not foolproof, but generally reasonable.


Thanks, I'll try it. I looked at the URL you posted, but couldn't figure
out what to look for to ascertain if it is an audio file. I assume that for
an audio file it will output something like "audio/something" and I could
check for the a match on the first five characters.

Shelly
Jul 26 '05 #3

P: n/a
On Tue, 26 Jul 2005 20:44:13 GMT, "Shelly" <sh************@asap-consult.com>
wrote:
There's the "mime magic" function:

http://uk2.php.net/mime_content_type

... which looks for magic numbers in the file to make a decent guess as to
what format a file is. Not foolproof, but generally reasonable.


Thanks, I'll try it. I looked at the URL you posted, but couldn't figure
out what to look for to ascertain if it is an audio file. I assume that for
an audio file it will output something like "audio/something" and I could
check for the a match on the first five characters.


Yes, that sounds right.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 26 '05 #4

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:ci********************************@4ax.com...
On Tue, 26 Jul 2005 20:44:13 GMT, "Shelly"
<sh************@asap-consult.com>
wrote:
There's the "mime magic" function:

http://uk2.php.net/mime_content_type

... which looks for magic numbers in the file to make a decent guess as
to
what format a file is. Not foolproof, but generally reasonable.


Thanks, I'll try it. I looked at the URL you posted, but couldn't figure
out what to look for to ascertain if it is an audio file. I assume that
for
an audio file it will output something like "audio/something" and I could
check for the a match on the first five characters.


Yes, that sounds right.


A wee bit of a problem. I did it and I get:

Fatal error: Call to undefined function: mime_content_type() in
/home/virtual/site23/fst/var/www/html/ssManageMusic.php on line 118

Now in www.php.net it says that the function is available for
(PHP 4 >= 4.3.0, PHP 5)

I downloaded and checked the php.ini on my server. I saw one comment that
mentioned something for PHP4.3 or greater, so I assume that my server is
running at least PHP 4.3. Any ideas?

Shelly
Jul 26 '05 #5

P: n/a
Shelly wrote:
I want to be able to verify that the file I upload is, indeed, an audio file.
You might look into

http://pecl.php.net/package/fileinfo

or as Andy said, mime_content_type(), which the Manual appears
to have deprecated now and you appear not to have available
right away.
I would like this function because I am reasoning that if the "type" obtained
from $_FILES['the_field_name']['type'] is not reliable for images, then it
probably isn't reliable for audio either.


It's 'not reliable' only insofar as it's straightforward for
somebody to send strange values, or the browser might be
unable to guess the intended type, or the browser might decide
not to give you a Content-Type at all. I would imagine it's
fairly accurate more often than not, although that's not to
say I wouldn't recommend performing further checks.

--
Jock
Jul 27 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.