Jump to content

Upload file restrictions


Krash

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.