Kevin Tantomi
Kevin Tantomi

Reputation: 23

Displaying .txt file in laravel View

I'm having a problem with trying to display data saved as .txt file in laravel blade view. the Laravel site was made by my predecessor and I'm assigned to add some features.

what I have tried :

is there any workaround or solution to this? how do you link the laravel route to a local file?

Upvotes: 1

Views: 5305

Answers (2)

Pavan
Pavan

Reputation: 345

you can use get() function, or asset() if your file is in storage/app/public then only

Storage::url(<path>);

works better,

if your file is in public directory simply use

{{ asset(path)}}

it will work

Upvotes: 1

ata
ata

Reputation: 1354

You can just read that file into variable and show it in your blade.

$txtFile = file_get_contents("test.txt");

or,

$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("webdictionary.txt"));
fclose($myfile);

Upvotes: 1

Related Questions