Jump to content

Multiple file types


NickLindeman

Recommended Posts

How do I go about limiting uploads to multiple file types?

 

Currently I am using..

 

elseif ($_FILES['file']['type'] != 'image/gif')
{
echo "Your file must be an image.";
}

 

I want to try and limit it to .gif, .jpg, and .png but I was wondering how I make it limit to the multiple file types.

 

Also I was wondering if it was possible to limit .gif files to non-animated .gifs.

Link to comment
https://forums.phpfreaks.com/topic/71444-multiple-file-types/
Share on other sites

How do I go about limiting uploads to multiple file types?

 

Currently I am using..

 

elseif ($_FILES['file']['type'] != 'image/gif')
{
echo "Your file must be an image.";
}

 

I want to try and limit it to .gif, .jpg, and .png but I was wondering how I make it limit to the multiple file types.

 

Also I was wondering if it was possible to limit .gif files to non-animated .gifs.

 

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/png"))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    die ("Error: " . $_FILES["file"]["error"]);
    }
  else
    {
    if (file_exists("uploads/" . $_FILES["file"]["name"]))
      {
      die ("File already exists");
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
      }
    }
  }
else
  {
  echo "GIF, JPEG, and PNG images only";
  }
?>

 

This works for me every time.

I don't think you can remove GIF animation unless you convert the GIF to another format with GD.

Link to comment
https://forums.phpfreaks.com/topic/71444-multiple-file-types/#findComment-359639
Share on other sites

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.