dsartain Posted February 9, 2007 Share Posted February 9, 2007 I'm starting to make a dynamic pic gallery for a friend, and most of her jpg files have the mime type if image/pjpeg. I want to make sure that she is only uploading images, but I want to allow more than just that one mime type to be uploaded (image/jpeg, image/gif...etc)...It's uploading the file properly, enough to determine the mime type anyway, but it keeps giving me the "You are attempting to upload a file that is not in the image/pjpeg, image/jpeg, image/gif, image/bmp, or image/png format" error...the code for the file upload and mime test is below. I think my array and foreach loop is right, but I can't think of what else could mess it up...ideas? $userfile_t=$_FILES['userfile_t']['tmp_name']; $userfile_t_name=$_FILES['userfile_t']['name']; $userfile_t_size=$_FILES['userfile_t']['size']; $userfile_t_type=$_FILES['userfile_t']['type']; $userfile_t_error=$_FILES['userfile_t']['error']; if($userfile_t_error>0) { echo "Problem: "; switch($userfile_t_error) { case 1: echo "File exceeded upload_max_filesize!"; break; case 2: echo "File exceeded max_file_size!"; break; case 3: echo "File only partially uploaded!"; break; case 4: echo "No file uploaded!"; break; } exit; } $mimeTypes = array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/png'); foreach ($mimeTypes as $type) { if ($userfile_t_type != $type) { echo "Problem: You are attempting to upload a file that is not in the image/pjpeg, image/jpeg, image/gif, image/bmp, or image/png format!<BR />"; echo "thumbnail<br />"; echo $userfile_t_type."<BR />"; exit; } } Link to comment https://forums.phpfreaks.com/topic/37796-problem-with-mime-type-array-when-uploading-files/ Share on other sites More sharing options...
Orio Posted February 9, 2007 Share Posted February 9, 2007 Use in_array(): if (!in_array($userfile_t_type, $mimeTypes)) echo "Problem..."; Orio. Link to comment https://forums.phpfreaks.com/topic/37796-problem-with-mime-type-array-when-uploading-files/#findComment-180803 Share on other sites More sharing options...
dsartain Posted February 9, 2007 Author Share Posted February 9, 2007 works perfectly, thanks! Link to comment https://forums.phpfreaks.com/topic/37796-problem-with-mime-type-array-when-uploading-files/#findComment-180809 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.