Search code examples
phpimageresizefile-type

PHP File Upload Recognition help!


SOLVED MY OWN QUESTION! THANKS EVERYONE FOR THE HELP :)

Ok. I'm having trouble with the code below recognizing the upload FILE TYPE and running the correct function. I can upload PNG just fine and it will convert and resize like it should, but GIF and JPEG don't and just return a black image. If I remove the png code and try the others individually they work. I can't figure this out at the moment why when I combine them they won't work. It's like together they all use whatever function comes first, instead of going by the FILE TYPE

if ($width > $max_width){
    $scale = $max_width/$width;
    if ($_FILE['image']['type'] = "image/png"){
    $uploaded = resizeImagePNG($large_image_location,$width,$height,$scale);
    } elseif ($_FILE['image']['type'] = "image/gif"){
    $uploaded = resizeImageGIF($large_image_location,$width,$height,$scale);
    } elseif ($_FILE['image']['type'] = "image/jpeg" || $_FILE['image']['type'] = "image/pjpeg"){
    $uploaded = resizeImageJPG($large_image_location,$width,$height,$scale);
    }
    session_start();
    $_SESSION['image2resize'] = $large_image_location;
    }else{
    $scale = 1;
    if ($_FILE['image']['type'] = "image/png"){
    $uploaded = resizeImagePNG($large_image_location,$width,$height,$scale);
    } elseif ($_FILE['image']['type'] = "image/gif"){
    $uploaded = resizeImageGIF($large_image_location,$width,$height,$scale);
    } elseif ($_FILE['image']['type'] = "image/jpeg" || $_FILE['image']['type'] = "image/pjpeg"){
    $uploaded = resizeImageJPG($large_image_location,$width,$height,$scale);
    }
    session_start();
    $_SESSION['image2resize'] = $large_image_location;
    }
}

Solution

  • FIGURED IT OUT!!!!!!!! The verification was screwing things up. Instead of checking if it's not a image, I checked if it was and it started working. NEW verification -> if ($mime == 'image/gif' || $mime == 'image/jpeg' || $mime == 'image/pjpeg' || $mime == 'image/png' || $_FILES['image']['size'] < 3000000){ working code here } else { error code here } . Thanks for all the help!