Jump to content

Need help with a condition


derekbelcher

Recommended Posts

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

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')

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.. :-[

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
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.