Same name and namespace in other branches
  1. 7.x includes/file.inc \file_unmanaged_save_data()
  2. 8.9.x core/includes/file.inc \file_unmanaged_save_data()
  3. 8.0.x core/includes/file.inc \file_unmanaged_save_data()
  4. 8.1.x core/includes/file.inc \file_unmanaged_save_data()
  5. 8.3.x core/includes/file.inc \file_unmanaged_save_data()
  6. 8.4.x core/includes/file.inc \file_unmanaged_save_data()
  7. 8.5.x core/includes/file.inc \file_unmanaged_save_data()
  8. 8.6.x core/includes/file.inc \file_unmanaged_save_data()
  9. 8.7.x core/includes/file.inc \file_unmanaged_save_data()
  10. 8.8.x core/includes/file.inc \file_unmanaged_save_data()

Saves a file 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.

Parameters

$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

file_save_data()

Related topics

9 calls to file_unmanaged_save_data()
AggregatorTestBase::getEmptyOpml in core/modules/aggregator/src/Tests/AggregatorTestBase.php
Creates a valid but empty OPML file.
AggregatorTestBase::getInvalidOpml in core/modules/aggregator/src/Tests/AggregatorTestBase.php
Creates an invalid OPML file.
AggregatorTestBase::getValidOpml in core/modules/aggregator/src/Tests/AggregatorTestBase.php
Creates a valid OPML file from an array of feeds.
ConfigExportUITest::testExport in core/modules/config/src/Tests/ConfigExportUITest.php
Tests export of configuration.
FileEntityNormalizer::denormalize in core/modules/hal/src/Normalizer/FileEntityNormalizer.php
Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize().

... See full list

File

core/includes/file.inc, line 953
API for handling file uploads and server file management.

Code

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);
}