bool CFile::SaveForDB( array &Fields,
The method is used to prepare data prior to inserting/updating a record in the data base, containing link to file. The method saves file to disk and returns the ID of the saved file via the input array to further insert/update the record in the data base. Static method.
Note: prior to version 7.1.0 the same actions were performed by the CDatabase::PrepareInsert and CDatabse::PrepareUpdate methods. Starting from version 7.1.0 the actions to save files and insertions into the data base are located between different methods.
Array of field values in the format "field_name1"=>"value1", "field_name2"=>"value2" [, ...].
The value is passed via the link.
|field||Field name in the arFields array that contains the file.|
|SavePath||Folder name (will be located inside the 'upload' folder) for file storage. |
Prior to version 12.0.8 the parameter was called dir.
True on success, false otherwise. The $arFields[$field] array element value will return the ID of the saved file from the "b_file" registrar table. If the file was deleted, false will be returned in this field. In case of failure, the element of the $arFields[$field] array will be deleted (unset).
Examples of use
$arFields["ATTACH_IMG"] = $_FILE["ATTACH_IMG"];
$arFields["ATTACH_IMG"]["MODULE_ID"] = "blog";
CFile::SaveForDB($arFields, "ATTACH_IMG", "blog");
$arInsert = $DB->PrepareInsert("b_blog_post", $arFields);