Bitrix Site Manager

CFile::CheckFile

string
CFile::CheckFile(
 array file,
 int max_size = 0,
 string mime_types = false,
 string extensions = false
)

The method CheckFile verifies the size, extension and mime type of the file. In case of an error, the method returns a string containing the error description.

Parameters

ParameterDescription
file Array with the file information in the format:

Array(
    "name" => "file name",
    "size" => "size",
    "tmp_name" => "temporary file path on server",
    "type" => "file type ",
    "del" => "flag (Y|N) specifying to delete"
             "the existing file from the database",
    "MODULE_ID" => "module name")
This array can be obtained, for example, by joining arrays $_FILES[field_name] and Array("del" => ${"field_name"."_del"}, "MODULE_ID" = "module_name").
max_size Maximum size of a file in bytes.
Optional. The default value is "0", which means no restriction applies.
mime_types Allowed mime type of a file (e.g. "image/"). Verification is performed using data received from a user, this is why you should use extensions for safer checks.
Optional. The default value is false, which means no restriction applies.
extensions Allowed file extensions separated with comma.
Optional. The default value is false, which means no restriction applies.

See Also

Example



<?
$arrFile = array_merge(
    $_FILES["ATTACHED_IMAGE"], 
    array("del" => ${"ATTACHED_IMAGE_del"}, "MODULE_ID" => "forum"));

$res = CFile::CheckFile($arrFile, 200, "image/", CFile::GetImageExtensions());
if (strlen($res)>0) $strError .= $res."<br>";
?>