Image upload security - reprocess with GD

前端 未结 2 1680
失恋的感觉
失恋的感觉 2020-12-18 08:58

I\'ve heard that the best way to handle uploaded images is to \"re-process\" them using the GD library and save the processed image. see: PHP image upload secu

2条回答
  •  失恋的感觉
    2020-12-18 09:13

    function isvalidjpeg($file) 
    { 
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    return is_resource($finfo) && 
           (finfo_file($finfo, $file) === 'image/jpeg') && 
           finfo_close($finfo);
    }
    if(isvalidjpeg($_FILES['file']['tmp_name'])) {
       $newIm = @imagecreatefromjpeg($_FILES['file']['tmp_name']); .....
    

提交回复
热议问题