3 ms·
Ummm, that statement is always going to be true. This isn't a PHP question this is a basic logic question. You really want... if (!(type == gif or type == jp
by pmorici 19y ago
Ummm, that statement is always going to be true. This isn't a PHP question this is a basic logic question.
You really want...
if (!(type == gif or type == jpeg)) { error }
or change your 'or' to an 'and' ie:
if (type!=gif and type!=jpeg) { error }
http://en.wikipedia.org/wiki/De_Morgan's_laws http://en.wikipedia.org/wiki/De_Morgan's_laws
- streblo 19y agoSo, what you're saying is, if the type isn't a gif OR if it isn't a jpeg, reject. The problem is that every picture isn't a gif or isn't a jpeg. jpeg images will be rejected because they aren't gifs, and gifs will be rejected because they aren't jpegs. You need to do what pmorici said and change this to an 'and' statement, or negate the entire statement you already have.
- technoguyrob 19y agoThis isn't the only problem. Not all gifs and jpegs use that MIME [1]. Try this: $allowed_image_types = array('image/gif', 'image/x-gif', 'image/pjpeg', 'image/jpeg', 'image/x-pjpeg', 'image/x-jpeg', 'image/x-jpg', 'image/jpg'); if (!in_array($type, $allowed_image_types)) { $error = 'ERROR: You can only upload GIF and JPG files.'; } [1] http://www.webmaster-toolkit.com/mime-types.shtml http://www.webmaster-toolkit.com/mime-types.shtml
- whalesalad 19y agoThis is the best method right here, hands down.