What if you try File::get('last.txt');?
Nov 22, 2015
4
Level 2
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?
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
Please or to participate in this conversation.