gpt4 book ai didi

php - Laravel 中 file_get_contents 的替代方法是什么?

转载 作者:行者123 更新时间:2023-12-04 01:16:39 37 4
gpt4 key购买 nike

file_get_contents($url)工作 但 Laravel 功能不起作用。

文件在此 URL 上可用

$url = "https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat";

这个简单的 PHP 函数正在工作并正在检索文件
$content = file_get_contents($url);

但是下面提到的所有这些 Laravel 函数都显示了这个错误:

"File does not exist at path https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat"



代码如下:
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;

最佳答案

我建议 guzzlehttp ( Github Page )

易于使用:

安装:

 composer require guzzlehttp/guzzle

发送请求并获得响应:
$client = new \GuzzleHttp\Client();
$res = $client->get($url);
$content = (string) $res->getBody();

关于php - Laravel 中 file_get_contents 的替代方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53993336/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com