file_get_contents($url)
is working but Laravel functions not working.
File is available at this URL
$url = "https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat";
this simple PHP function is working and retrieving the file
$content = file_get_contents($url);
but all these Laravel functions which mentioned below are showing this error :
"File does not exist at path https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat"
Code is available below:
use File; // i have included this before class
use Storage; // i have included this before class
$url = "https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat";
$content = File::get($url); // not working
$content = Storage::get($url); // not working
$content = File::get(url($url)); // not working
$content = file_get_contents($url); // working fine
return $content;
The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string. It will use memory mapping techniques, if this is supported by the server, to enhance performance.
file — Reads entire file contents into an array of lines. file_get_contents — Reads entire file contents into a string.
Return Values ¶ The function returns the read data or false on failure. This function may return Boolean false , but may also return a non-Boolean value which evaluates to false . Please read the section on Booleans for more information.
Unfortunately, file_get_contents() is a dangerous function when used with data obtained from user input, as it is the case. Using it could allow diverse kinds of attacks, from Denial of Service to loading of remote malicious resources.
I suggest guzzlehttp (Github Page)
Easy Usage:
Installation:
composer require guzzlehttp/guzzle
Send request and get response:
$client = new \GuzzleHttp\Client();
$res = $client->get($url);
$content = (string) $res->getBody();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With