marcosdipaolo's avatar

File not found on resource_path()

The line resource_path('email-attachments/' . $filename) is throwing a "File not found" error when the file actually exists. I checked it with file_exists which returns true. I'm working with docker but the problem persist inside and outside the container. I'm working in an quite old app with Laravel 5.4.

file_exists(resource_path('email-attachments/' . $filename))
true
\Storage::copy(
    resource_path('email-attachments/' . $filename),
    storage_path('app/email-attachments/' . $filename)
);
In Filesystem.php line 388:
File not found at path: var/www/html/resources/email-attachments/filename.pdf

thanks in advance

0 likes
2 replies
petrit's avatar
petrit
Best Answer
Level 20

resource_path() is a path to resource directory, so storage_path() is a path storage directory. Maybe File facade will work

\File::copy(
    resource_path('email-attachments/' . $filename),
    storage_path('app/email-attachments/' . $filename)
);

Also you have to check if directories exists

marcosdipaolo's avatar

SOLVED I was using Storage instead of File, or just the native copy

Edit: Exactly @petrit !!!! thanks!

Please or to participate in this conversation.