DiegoP.
DiegoP.

Reputation: 45737

Limit file uploads to mp3 and WAV

I use this code to limit upload of images.

How do I use the same code to limit uploads of only mp3 and WAV files?

Thank you so much!

if ((($_FILES["Artwork"]["type"] == "image/gif")
|| ($_FILES["Artwork"]["type"] == "image/jpeg")
|| ($_FILES["Artwork"]["type"] == "image/jpg")
|| ($_FILES["Artwork"]["type"] == "image/pjpeg"))
&& ($_FILES["Artwork"]["size"] < 20000000))
  {
  if ($_FILES["Artwork"]["error"] > 0)
    {
    //echo "Return Code: " . $_FILES["Artwork"]["error"] . "<br />";
    }else{
      move_uploaded_file($_FILES["Artwork"]["tmp_name"],
      $path_image . $imageName);
      }
    }else{
    //echo "invalid file";
    }

Upvotes: 0

Views: 1020

Answers (2)

lorenzo-s
lorenzo-s

Reputation: 17010

As said, don't use $_FILES["file"]["type"], it's not safe. Use http://www.php.net/manual/en/function.finfo-file.php instead (see example, it's quite self-explanatory).

To know the mimetype of MP3 and WAV file, search here: http://www.asciitable.it/mimetypes.asp

Upvotes: 0

Arnaud Le Blanc
Arnaud Le Blanc

Reputation: 99879

Don't use $_FILES["Artwork"]["type"], this is specified by the client, and he can put anything he wants here.

Upvotes: 2

Related Questions