1
\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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I passed the path instead of using the Storage facade and process it from there. I will update you when your answer works. Thanks!
Almost a month and I forgot to update. The problem was ->get() fetches the content. I fetched the file with something like storage_path('app/public/verify') . "/" . $file If there's a better solution, please do tell!
0

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.