use*_*609 0 php curl file-get-contents
有没有替代file_get_contents?这是我遇到问题的代码:
if ( !$img = file_get_contents($imgurl) ) { $error[] = "Couldn't find the file named $card.$format at $defaultauto"; }
else {
if ( !file_put_contents($filename,$img) ) { $error[] = "Failed to upload $filename"; }
else { $success[] = "All missing cards have been uploaded"; }
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用cURL,但无法弄清楚如何完成这项工作.任何帮助表示赞赏!
file_get_contents有很多替代方案我在下面发布了几个替代方案.
FOPEN
function fOpenRequest($url) {
$file = fopen($url, 'r');
$data = stream_get_contents($file);
fclose($file);
return $data;
}
$fopen = fOpenRequest('https://www.example.com');// This returns the data using fopen.
Run Code Online (Sandbox Code Playgroud)
卷曲
function curlRequest($url) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($c);
curl_close($c);
return $data;
}
$curl = curlRequest('https://www.example.com');// This returns the data using curl.
Run Code Online (Sandbox Code Playgroud)
您可以使用这些可用选项之一与存储在变量中的数据来预先形成您需要的内容.
| 归档时间: |
|
| 查看次数: |
3878 次 |
| 最近记录: |