Bitrix Site Manager

CFile::SaveFile

mixed
CFile::SaveFile(
 array file,
 string save_path
)

The method SaveFile saves a file and registers it in the file table (b_file).

Parameters

ParameterDescription
file Array with file data in the following format:
Array(
    "name" => "file name",
    "size" => "size",
    "tmp_name" => "temporary path on server",
    "type" => "file type",
    "old_file" => "ID of old file",
    "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").
save_path Path to folder with (relative to /upload).

See Also

Example



<?
if (strlen($save)>0 && $REQUEST_METHOD=="POST")
{
    $arIMAGE = $_FILES["IMAGE_ID"];
    $z = $DB->Query("SELECT IMAGE_ID FROM b_vote WHERE ID='$ID'", 
                    false, $err_mess.__LINE__);
    $zr = $z->Fetch();
    $arIMAGE["old_file"] = $zr["IMAGE_ID"];
    $arIMAGE["del"] = ${"IMAGE_ID_del"};
    $arIMAGE["MODULE_ID"] = "vote";
    if (strlen($arIMAGE["name"])>0 || strlen($arIMAGE["del"])>0) 
    {
        $fid = CFile::SaveFile($arIMAGE, "vote");
        if (intval($fid)>0) $arFields["IMAGE_ID"] = intval($fid); 
        else $arFields["IMAGE_ID"] = "null";
        $DB->Update("b_vote",$arFields,
                    "WHERE ID='".$ID."'",$err_mess.__LINE__);
    }
}
?>