2

I have this line:

$local_document_path = storage_path() . "/app/file/myfile.pdf";

$myfile = Storage::get($local_document_path);

And I get a FileNotFoundException error.

Now I checked the variable and seems correct, and I double checked again by copying the path to clipboard and pasting it:

dd($local_document_path == $copypasted_path)

It returns true. This means that the path is 100% correct, yet it does not work with storage. I have also tried by removing storage_path(); and it does not work either.

Any help?

Thanks in advance.

8
  • dd($local_document_path = $copypasted_path) returns true? This is an assignment not a comparison. Unless the value of $copypasted_path is boolean true, that can never return true Commented Dec 7, 2017 at 22:43
  • @Paras Sorry it was == not = I typed it wrong. It is still the same and it return true. Commented Dec 7, 2017 at 22:45
  • The docs say "Remember, all file paths should be specified relative to the 'root' location configured for the disk" but you've given an absolute path. That's likely the issue. Is there a folder called app within your storage folder in Laravel? Commented Dec 7, 2017 at 22:47
  • @ceejayoz Yes, absolutely. Commented Dec 7, 2017 at 22:50
  • If so, Storage::get('app/file/myfile.pdf'); should do it, assuming storage/app/file/myfile.pdf a) exists and b) is readable by the webserver. Commented Dec 7, 2017 at 22:50

1 Answer 1

4

Your Storage::get calls should use a path relative to the root of the storage disk. The default storage disk is configured to be storage_path('app'), so you'll need Storage::get('file/myfile.pdf').

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.