file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME)
drupal/includes/file.inc, line 1125
Save a string to the specified destination and create a database file entry.
@see file_unmanaged_save_data()
$data A string containing the contents of the file.
$destination A string containing the destination location. If no value is provided then a randomly name will be generated and the file saved in Drupal's files directory.
$replace Replace behavior when the destination file already exists:
A file object, or FALSE on error.
| Name | Description |
|---|---|
| File interface | Common file handling functions. |
function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
global $user;
if ($filepath = file_unmanaged_save_data($data, $destination, $replace)) {
// Create a file object.
$file = new stdClass();
$file->filepath = $filepath;
$file->filename = basename($file->filepath);
$file->filemime = file_get_mimetype($file->filepath);
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
return file_save($file);
}
return FALSE;
}