Documentation

IsImage

string
CFile::IsImage(
 string file_name,
 mixed mime_type = false
)

The method checks file extension and specified file MIME type. Returns true If the file extension and MIME type corresponds to an image, or "false" otherwise. Static method.

Parameters

ParameterDescription
file_name Short file name (without path).
mime_type MIME file type (for example, "image/").
Optional parameter. By default value is "false" which disables check for MIME type.
Prior to version 4.0.4 it was called content_type.

See Also

Examples of use

<?
if ($rsFiles = CTicket::GetFileList($v1="s_id", $v2="asc", array("HASH"=>$hash))) :
  if ($arFile = $rsFiles->Fetch()) :
    $filename = $_SERVER["DOCUMENT_ROOT"]."/".COption::GetOptionString("main", "upload_dir", "upload")."/".$arFile["SUBDIR"]."/".$arFile["FILE_NAME"];
    if ($f = fopen($filename, "rb"))
    {
      $is_image = CFile::IsImage($arFile["FILE_NAME"], $arFile["CONTENT_TYPE"]);
      // if the image file is confirmed then
      if ($is_image) 
      {
        // pass as the image type 
        header("Content-type: ".$arFile["CONTENT_TYPE"]);
        header("Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0"); 
        header("Expires: 0"); 
        header("Pragma: public"); 
        while ($buffer = fread($f, 4096)) echo $buffer;
      }
      else // otherwise
      {
        // pass as text 
        header("Content-type: text/html; charset=".LANG_CHARSET);
        header("Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0"); 
        header("Expires: 0"); 
        header("Pragma: public"); 
        echo "<pre>";
        while ($buffer = fread($f, 4096)) echo htmlspecialchars($buffer);
        echo "</pre>";
      }
      fclose ($f);
      die();
    }
  endif;
endif;
?>


© «Bitrix24», 2001-2022
Up