SaveFile
Description and parameters
mixed CFile::SaveFile( array file, string save_path, bool ForceMD5=false, bool SkipExt=false, $dirAdd='', bool checkDuplicates = true )
The method saves a file and registers it in the file table (b_file). Static method.
Parameters
Parameter | Description | Available fr om version |
---|---|---|
file |
Array of 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 existing file - any non-blank value", "MODULE_ID" => "module name", "description" => "file description", "content" => "file content. A file can be saved, with its content specified, not only an array, retrieved when loading by browser."This type of array can be obtained, for example, by joining arrays $_FILES[field_name] и Array("del" => ${"field_name"."_del"}, "MODULE_ID" = "module_name");
|
|
save_path | Path to folder storing the files (relative to /upload folder). | |
ForceMD5 | Optional. Default value false. | |
SkipExt | Optional. Default value false. | |
dirAdd | 7.0.0 | |
checkDuplicates | Duplicate check. Optional. Default value true. |
Returned value
The method returns numerical ID of file saved and registered in the system.
See Also
Examples of use
<? if (strlen($save)>0 && $REQUEST_METHOD=="POST") { $arIMAGE = $_FILES["IMAGE_ID"]; $z = $DB->Query("SEL ECT IMAGE_ID FR OM 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,"WH ERE ID='".$ID."'",$err_mess.__LINE__); } } ?>
© «Bitrix24», 2001-2024