NickLindeman Posted October 1, 2007 Share Posted October 1, 2007 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 More sharing options...
sljaxon Posted October 1, 2007 Share Posted October 1, 2007 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 More sharing options...
NickLindeman Posted October 2, 2007 Author Share Posted October 2, 2007 I can't get it to work with elseif. Link to comment https://forums.phpfreaks.com/topic/71444-multiple-file-types/#findComment-359729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.