Jump to content

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

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.