PHP 7 Mime和PDF验证

这在PHP 5中有效,但是现在不行了:


if (function_exists('finfo_open')) {

  $mime = finfo_open(FILEINFO_MIME_TYPE);

  $mime_type = finfo_file($mime, "FILE-PATH");

  if($mime_type == array("application/pdf", "image/jpeg", "image/png"))

    echo "file is pdf";

  else

    echo "file is not pdf";

  finfo_close($mime);

}


繁花如伊
浏览 184回答 1
1回答

慕无忌1623718

您将字符串与数组进行了比较,这是正确的代码:if (function_exists('finfo_open')) {  $mime = finfo_open(FILEINFO_MIME_TYPE);  if (in_array(finfo_file($mime, 'FILE-PATH'), array('application/pdf', 'image/jpeg', 'image/png')))    echo 'file is pdf';  else    echo 'file is not pdf';  finfo_close($mime);}
打开App,查看更多内容
随时随地看视频慕课网APP