rcorlew Posted May 16, 2007 Share Posted May 16, 2007 Let me start off by saying that the code works perfectly, the only thing is that I would like the users to be able to use more than one image format for their pictures. Currently the script only accepts jpg, but I would like to allow png and gif. Here is my code: if ($_FILES['userfile']['type'] != 'image/jpg') I am also using an array to detect images in the directory that works fine, I have not figured out how to use an array as the image/$type. $file_t = array('jpeg', 'jpg', 'ico', 'png', 'gif', 'bmp'); Any help would be mucho appreciado. Link to comment https://forums.phpfreaks.com/topic/51608-solved-a-little-help-with-this-very-small-piece-of-code/ Share on other sites More sharing options...
radar Posted May 16, 2007 Share Posted May 16, 2007 if ($_FILES['userfile']['type'] == 'image/jpg' || $_FILES['userfile']['type'] == 'image/ico' || etc... etc... ) Link to comment https://forums.phpfreaks.com/topic/51608-solved-a-little-help-with-this-very-small-piece-of-code/#findComment-254219 Share on other sites More sharing options...
neel_basu Posted May 16, 2007 Share Posted May 16, 2007 <?php $file_t = array('jpeg', 'jpg', 'ico', 'png', 'gif', 'bmp'); preg_match('/image\/(\w+)/', $txt, $m); if(in_array($m[1], $file_t)) { //Yes Matched } ?> Link to comment https://forums.phpfreaks.com/topic/51608-solved-a-little-help-with-this-very-small-piece-of-code/#findComment-254221 Share on other sites More sharing options...
phast1 Posted May 16, 2007 Share Posted May 16, 2007 How about something like this: $mime_types = array('image/jpeg', 'image/gif', 'image/bmp'); // add more if you want for ($i = 0; $i < sizeof($mime_types); $i++) { if ($_FILES['userfile']['type'] == $mime_types[$i]) { // MIME type is valid, do something useful here } } Link to comment https://forums.phpfreaks.com/topic/51608-solved-a-little-help-with-this-very-small-piece-of-code/#findComment-254223 Share on other sites More sharing options...
rcorlew Posted May 16, 2007 Author Share Posted May 16, 2007 I used radar's solution, works great, tweaked my code a little and presto. Link to comment https://forums.phpfreaks.com/topic/51608-solved-a-little-help-with-this-very-small-piece-of-code/#findComment-254227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.