derekbelcher Posted June 16, 2009 Share Posted June 16, 2009 I am working on a file upload script. I want to limit the upload to a particular size in pixels? is that possible. I know how to do it in bytes. Also, I want to check and make sure that only .gif and .jpg files are uploaded. I tried: if ($uploaded_type =="image/gif") { $ok=0; } it works, but how do I allow .jpg in the same statment? Thanks, Link to comment https://forums.phpfreaks.com/topic/162434-need-help-with-a-condition/ Share on other sites More sharing options...
akitchin Posted June 16, 2009 Share Posted June 16, 2009 MIME types shouldn't generally be trusted. you'll want to check those AND the extension to ensure that you're only getting the file type you want. as for restricting the dimensions of the image, have a look at this function: getimagesize() in order to add conditions, you can link them together using && for "and," || for "or." if ($uploaded_type =="image/gif" || $uploaded_type == 'image/jpeg') Link to comment https://forums.phpfreaks.com/topic/162434-need-help-with-a-condition/#findComment-857409 Share on other sites More sharing options...
derekbelcher Posted June 16, 2009 Author Share Posted June 16, 2009 thanks that helps a lot Link to comment https://forums.phpfreaks.com/topic/162434-need-help-with-a-condition/#findComment-857410 Share on other sites More sharing options...
cs.punk Posted June 16, 2009 Share Posted June 16, 2009 thanks that helps a lot So our gonna only allow users with a certain image res to upload?... Is'nt that a strain on the 'user/uploader'? See my 'Resize JPEG image to 320x200 size?' that might be better?... Just trying to help Link to comment https://forums.phpfreaks.com/topic/162434-need-help-with-a-condition/#findComment-857417 Share on other sites More sharing options...
cs.punk Posted June 17, 2009 Share Posted June 17, 2009 thanks that helps a lot So our gonna only allow users with a certain image res to upload?... Is'nt that a strain on the 'user/uploader'? See my 'Resize JPEG image to 320x200 size?' that might be better?... Just trying to help Sorry for that face lol, have no idea where it came from.. Link to comment https://forums.phpfreaks.com/topic/162434-need-help-with-a-condition/#findComment-857825 Share on other sites More sharing options...
Yesideez Posted June 17, 2009 Share Posted June 17, 2009 As a side note for the OP... Many different types of files have identifying strings embedded in the files at certain locations. For example, GIF files start "GIF" followed by a revision number (most common being GIF87) and an animated GIF would look something like this: GIF87a You can do an extra check for files which must be of specific type (don't rely on this method alone either!) with something like this: if ($file[0]=='G' && $file[1]=='I' && $file[2]=='F') { //looks like the file is a GIF } Link to comment https://forums.phpfreaks.com/topic/162434-need-help-with-a-condition/#findComment-857840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.