2013-12-21 86 views
0

是否有替代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"; } 
} 

我试图使用卷曲,但不能完全弄清楚如何做到这是什么完成。任何帮助表示赞赏!

+0

请参阅[本答案](http://stackoverflow.com/a/20562385/1438393)了解'curl_get_contents()'函数。 –

回答

5

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. 

卷曲

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. 

你可以使用与存储在一个变量中的数据,这些可用选项之一瓶坯你需要什么。