O'Reilly logo

Drupal 8 Module Development by Daniel Sipos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with unmanaged files

Working with unmanaged files is actually pretty similar to doing so with managed files, except that they are not tracked in the database using the File entity type. There is a set of helper functions similar to what we've seen for managed files that do the same things--but they have the word unmanaged in them. Let's see some examples.

To save a new file, we do almost like we did before:

$image = file_get_contents('products://tv.jpg');
$path = file_unmanaged_save_data($image, 'public://tv.jpg', FILE_EXISTS_REPLACE);

We load the file data from wherever and use the file_unmanaged_save_data() the same way as we did file_save_data(). The difference is that the file is going to be saved but no database record is created. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required