tuytoosh's avatar

Read a .txt file in laravel 5 :(

Hi , I have a .txt file like last.txt in my project root. I am using following code for show the content of file :

$contents = File::get(url('last.txt'));
        dd($contents);

but I have this error : File does not exist at path http://didany.net/last.txt where is the problem?

0 likes
4 replies
accent-interactive's avatar
Level 14

You need to know where your file lives. You also need a path to get there.

In you example you used url(), which tries to access you file over the web, using http.

Laravel has handy path helper functions, check them out in the manual.

E.g., if your file is located in the storage folder, you could do

File::get(storage_path('myfolder/test.txt'));
3 likes
shezy26's avatar

You need to specify disk name with storage, Like this: Storage::disk('local')->put('file.txt','content');

Please or to participate in this conversation.