file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME)
drupal/includes/file.inc, line 523
Save a string to the specified destination.
$data A string containing the contents of the file.
$dest A string containing the destination location.
$replace Replace behavior when the destination file already exists.
A string containing the resulting filename or 0 on error
| Name | Description |
|---|---|
| File interface | Common file handling functions. |
function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
$temp = file_directory_temp();
$file = tempnam($temp, 'file');
if (!$fp = fopen($file, 'wb')) {
drupal_set_message(t('The file could not be created.'), 'error');
return 0;
}
fwrite($fp, $data);
fclose($fp);
if (!file_move($file, $dest, $replace)) {
return 0;
}
return $file;
}