Reputation: 81
\Storage::disk('verify_files')->put('verify-' . $fileCode[3], $fileCode[0]);
$attach = \Storage::get(storage_path('app/public/verify') . '/' . 'verify-' . $fileCode[3]);
I am using the code above to generate and fetch the file.
Here is the filesystem I use:
'verify_files' => [
'driver' => 'local',
'root' => storage_path('app/public/verify'),
'visibility' => 'public',
],
When I test it with file_exists(), it returns true but laravel returns FileNotFoundException in FilesystemAdapter.php line 61:
Am I missing something here?
Upvotes: 1
Views: 5507
Reputation: 164
I was getting the same error as you, except I've been using a different method to you:
$parse = new Parsedown();
$url = url('about.md'); // This would fail, because it returns absolute
$url = 'about.md'; // the file is living in the root directory of public. This would succeed, because it's relative
try { // catch file not found errors
$about = File::get($url);
} catch (Illuminate\Filesystem\FileNotFoundException $exception) {
die ('Bad File');
}
echo $parse->text($about);
This came from a combination of this page and when @SArnab above mentioned about the path not needing to be absolute.
Besides me using a different method, the only problem I had before was that I was using an absolute path rather than a relative one which I'm using now.
I just thought I'd add in this alternative method to getting file contents in Laravel 5.2.
Enjoy!
Upvotes: 0
Reputation: 585
The get
method of the Storage facade will automatically look into the directory of the default disk. In this case, you are passing in the absolute path to the file using storage_path
, which is redundant because it will look inside the storage/app
directory as it is.
Instead, do Storage::disk('verify_files')->get('verify-' . $fileCode[3])
;
Use storage_path
when you need absolute paths to files and directories.
Upvotes: 2