I am trying to attach a file in the custom module's directory to every new node created for a content type. How do I create the file object? The following code gives me an error.
$uri1 = file_unmanaged_copy('checklist1.pdf', 'public://checklist1.pdf', FILE_EXISTS_REPLACE); $file1 = File::Create([ 'uri' => $uri1, ]); $file1->save();
The error I get is the following one:
The specified file checklist1.pdf could not be moved/copied because no file by that name exists. Please check that you supplied the correct filename.
To add, this code is in the module file inside a hook.