Jump to content

Recommended Posts

 

Trying to restrict file uploads to mp3 files only using this -

 

 

if ($uploaded_type != "audio/mpeg")

{

echo "You may only upload mp3 files.<br><br>";

$ok=0;

}

 

 

It does not recognize mp3s, and will not allow any file types.  It works for other types (i.e., text/html).

 

What am I doing wrong?

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/194435-upload-file-restrictions/
Share on other sites

Unfortunately, there is a gap between the actual defined and registered mime types (which were originally defined for SMTP email) http://www.iana.org/assignments/media-types/ and what each browser does (for example the x- types are non-standard and are not registered.)

 

http://en.wikipedia.org/wiki/Internet_media_type

 

Best bet is to test actual files in the target browsers.

$filetype = explode("/", $uploaded_type);

if ( stristr($filetype[0], "audio") === false && stristr($filetype[1], "mpeg") === false && stristr($filetype[1], "mpa") === false)
{
echo "You may only upload mp3 files.<br ><br >";
$ok=0;
}

 

You could try that?

 

//EDIT

 

Added MPA check after reading wikipedia link.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.