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. ...