SaveFile
Description and parameters
bool CPosting::SaveFile( int ID, array file );
Method adds an attachment to a posting by saving and registering this attachment in the file table (b_file). Non-static method.
Parameters
Parameter | Description | Available from version |
---|---|---|
ID | Post ID. | |
file | Array with file data with the following format:Array( "name" => "file name", "size" => "size", "tmp_name" => "temporary server path", "type" => "uploaded file type");Array of this type can be sourced directly from $_FILES[field name] |
Returned values
In case attachment has been saved successfully, returns a registered file ID. Otherwise returns false, and variable class LAST_ERROR contains an error message.
Examples
if (strlen($save)>0 && $REQUEST_METHOD=="POST") { $cPosting=new CPosting; $file_id = $cPosting->SaveFile($ID, $_FILES["FILE_TO_ATTACH"]); if($file_id===false) strError .= "Error saving attachment."."
"; }
© «Bitrix24», 2001-2024