Lodius2000 Posted July 20, 2008 Share Posted July 20, 2008 heres what i have, trying to error check that an uploaded file has a jpg extension heres what i got just drawing a blank on the operator, please check my array syntax too please <?php $str = '1111111111.jpg'; //would contain uploaded file's name list($file, $ext) = explode('.', $str); print "$file is file<br /> $ext is ext<br />";//for error checking purposes $extentions = array(0 => 'jpg', 1 => 'jpeg'); if ($ext != $extentions){ print "gimme jpg please!"; } else { print "thats a jpg"; } ?> also is there a way to actually read the file and determine if its a particular type so that someone cant upload a tiff called blah.jpg? Link to comment https://forums.phpfreaks.com/topic/115747-solved-string-not-equal-to-array-element-whats-the-operator/ Share on other sites More sharing options...
cooldude832 Posted July 20, 2008 Share Posted July 20, 2008 look at my is_img function on the page http://www.phpfreaks.com/forums/index.php/topic,207663.0.html and then just adjust the valid "image_types" array to suite your needs. Link to comment https://forums.phpfreaks.com/topic/115747-solved-string-not-equal-to-array-element-whats-the-operator/#findComment-595030 Share on other sites More sharing options...
joquius Posted July 20, 2008 Share Posted July 20, 2008 The failure is due to the fact that $ext is a value and $extensions is an array. What you would need is "!in_array ($ext, $extensions)" and not "$ext != $extensions". Apart from that, you're better off using regex for this: $extensions = array ("jpg", "jpeg"); if (!preg_match ("/\.(".implode ("|", $extensions).")$/", $file)) // where $file is the fullname of the file Link to comment https://forums.phpfreaks.com/topic/115747-solved-string-not-equal-to-array-element-whats-the-operator/#findComment-595031 Share on other sites More sharing options...
Lodius2000 Posted July 20, 2008 Author Share Posted July 20, 2008 joquius i was thinking regex but i am terrible at it so thanks for the code, will definatly work better that what i got edit: so heres another question, how do you get the name of the file, or can i just use $_POST['uploaded_file'], does that store the filename in addition to the file data? or is there something else I need to do to get the name Link to comment https://forums.phpfreaks.com/topic/115747-solved-string-not-equal-to-array-element-whats-the-operator/#findComment-595036 Share on other sites More sharing options...
cooldude832 Posted July 21, 2008 Share Posted July 21, 2008 verifying the extension is less secure then actually open the image and reading some data to verify its content is a valid image file I can make a file that is really an executable in nature but call it a .jpg and sneak by your test Link to comment https://forums.phpfreaks.com/topic/115747-solved-string-not-equal-to-array-element-whats-the-operator/#findComment-595082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.