2013-12-21 5 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"; } 
} 

Я попытался с помощью Curl, но не мог понять, как сделать то, что это достижение. Любая помощь приветствуется!

+0

См. [Этот ответ] (http://stackoverflow.com/a/20562385/1438393) для функции 'curl_get_contents()'. –

ответ

5

Есть много альтернатив file_get_contents Я опубликовал несколько альтернатив ниже.

Еореп

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. 

Вы можете использовать один из доступных вариантов с данными, хранящимися в переменной преформ, что вам нужно.

Смежные вопросы