Documentation

CheckFile

string
CFile::CheckFile(
 array file,
 int max_size = 0,
 string mime_types = false,
 string Ext = false,
 bool ForceMD5=false,
 bool SkipExt=false
)

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

Parameters

ParameterDescription Available from version
file Array with the file data of the following format:

Array(
    "name" => "file name",
    "size" => "size",
    "tmp_name" => "temporary path to file on the server",
    "type" => "type of loaded file",
    "del" => "flag - specifies if an existing file is to be deleted from the database (Y|N)",
    "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 file size (bytes).
Optional parameter . By default - "0" - without limits.
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.
Ext Comma-separated permitted file extensions.
Optional parameter. By default - "false" - without limits.
File Extensions must be specified without a period, for example, not as .pdf, but as pdf. To verify the permissible extensions and the current extension of the loaded file, the current extension is retrieved by the CFile::GetFileExtension method, which returns the extension name without a period.
ForceMD5 Optional parameter. By default - "false".
SkipExt Optional parameter. By default - "false".

See Also

Examples of use

<?
$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>";
?>


© «Bitrix24», 2001-2024
Up