1. drupal
    1. 8
    2. 7
8 – 7 file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME)

Save a string to the specified destination without invoking file API.

This function is identical to file_save_data() except the file will not be saved to the {file_managed} table and none of the file_* hooks will be called.


$data A string containing the contents of the file.

$destination A string containing the destination location. This must be a stream wrapper URI. If no value is provided, a randomized name will be generated and the file will be saved using Drupal's default files scheme, usually "public://".

$replace Replace behavior when the destination file already exists:

Return value

A string with the path of the resulting file, or FALSE on error.

See also


Related topics

▾ 12 functions call file_unmanaged_save_data()

AggregatorTestCase::getEmptyOpml in modules/aggregator/aggregator.test
Create a valid but empty OPML file.
AggregatorTestCase::getInvalidOpml in modules/aggregator/aggregator.test
Create an invalid OPML file.
AggregatorTestCase::getValidOpml in modules/aggregator/aggregator.test
Create a valid OPML file from an array of feeds.
drupal_build_css_cache in includes/
Aggregates and optimizes CSS files into a cache file in the files directory.
drupal_build_js_cache in includes/
Aggregates JavaScript files into a cache file in the files directory.
FileUnmanagedSaveDataTest::testFileSaveData in modules/simpletest/tests/file.test
Test the file_unmanaged_save_data() function.
file_example_read_submit in examples/file_example/file_example.module
Submit handler for reading a stream wrapper.
file_example_unmanaged_write_submit in examples/file_example/file_example.module
file_save_data in includes/
Save a string to the specified destination and create a database file entry.
system_retrieve_file in modules/system/system.module
Attempts to get a file using drupal_http_request and to store it locally.
_color_save_stylesheet in modules/color/color.module
Save the rewritten stylesheet to disk.
_locale_rebuild_js in includes/
(Re-)Creates the JavaScript translation file for a language.


includes/, line 1893

function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
  // Write the data to a temporary file.
  $temp_name = drupal_tempnam('temporary://', 'file');
  if (file_put_contents($temp_name, $data) === FALSE) {
    drupal_set_message(t('The file could not be created.'), 'error');
    return FALSE;

  // Move the file to its final destination.
  return file_unmanaged_move($temp_name, $destination, $replace);