Reputation: 290
Laravel is not finding my file. I have a file with the following path:
C:\xampp\htdocs\IRB Source\storage\app\documents\Consent_Document.docx
I am trying to copy this file into a new file. I have the following in my controller:
File::copy(storage_path('app/documents/' . $document), storage_path('app/project/' .$id. '/' . $document));
When I debug with the following command:
dd(storage_path('app/documents/' . $document))
I get the proper path above. But Laravel is saying no file exists.
Upvotes: 0
Views: 83
Reputation: 8479
That's because directory app/project/{$id}
is not created yet.
You can ensure directory exists before copying as the following way:
$file = storage_path("app/documents/{$document}");
$dir = storage_path("app/project/{$id}");
if (!File::isDirectory($dir)) {
File::makeDirectory($dir, 0755, true, true);
}
File::copy($file, "{$dir}/{$document}");
Upvotes: 1