Jump to content

validating mime types


r08m

Recommended Posts

I am doing a script that uploads files but I need the users only to be able to upload JPEG images.  I have developed the following code which is unusable since the expression always comes to true:

[code]
$mimetype = $arch_info['type'];
if(is_uploaded_file($arch_info['tmp_name'])){
    if (($mimetype != "image/jpeg") || ($mimetype != "image/pjpeg")){
        header("location:./upsimgs.php?status=tipoimg");
        exit;
}
[/code]

I have checked the type of data that the "type" property returns, which returns a "string" and strip it with the code below to check if it had any special characters to no avail.

[code]
echo $mimetype . "<br>";
for($contador=0;$contador < strlen($mimetype); $contador++){
  $letra=substr($mimetype,$contador,1);
  echo $letra . ord($letra) . "<br>";
}
[/code]


This is not for security purposes just to make the user uploads the correct type since these files will be uploaded to another ODBC database (which I will love to have access to and change many things) that accepts only JPEGS and file size less than 190KB.

I'm pretty sure that what I have is a logic error but I can't see it.  Please I need your help!

Thanks in advanced.

Rob Muro
Link to comment
Share on other sites

I didn't find the best solution but I figured:

[code]
if(is_uploaded_file($file_info['tmp_name'])){
  if ($file_info['type'] != "image/pjpeg"){
    if($file_info['type'] != "image/jpeg"){
      header("location:./upsimgs.php?status=imgtype");
      exit;
    }
  }
}
[/code]

an it worked!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.