file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME)
Saves a file to the specified destination and creates a database entry.
Parameters
string $data: A string containing the contents of the file.
string|null $destination: (optional) A string containing the destination URI. This must be a stream wrapper URI. If no value or NULL is provided, a randomized name will be generated and the file will be saved using Drupal's default files scheme, usually "public://".
int $replace: