Angel Miladinov
Angel Miladinov

Reputation: 1655

Laravel maximum execution time error when trying to open .txt file

I have a .txt file with countries and their codes and I want to get the contents from it and insert into the database. But when why try to open the file using the php function fopen() it throws maximum execution time error here's the code: web.php:

Route::get('/countries', 'PageController@insertCountries');

PageController:

public function insertCountries()
{
   $file = fopen(asset('databases/countries.txt'), 'r');
    return 'ok';
}

The size of the file is 6KB. I am using Laravel 5.4 EDIT: the file is in mu public folder in folder databases

Upvotes: 1

Views: 143

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163898

If you want to open local file, use File facade to work directly with filesystem, also you shouldn't use asset() helper. So, do something like this instead:

$file = File::get('/full/path/to/the/file/countries.txt');

Upvotes: 3

Related Questions