- A+
所属分类:PHP
通常我们使用file_get_contents来获取一个本地文件或者网络文件内容。在请求网络文件的时候,比如要设置请求超时间,或者cookie这些。
// Create a stream
$opts = [
"http" => [
"method" => "GET",
"header" => "Accept-language: en\r\n" .
"Cookie: foo=bar\r\n",
"timeout" => 3 //time out 3 seconds
]
];
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
建议网络文件还是使用Curl类库.
- 我的微信
- 这是我的微信扫一扫
-
- 我的微信公众号
- 我的微信公众号扫一扫
-