2015-12-31 4 views
0

Я пытаюсь загрузить динамическую сгенерированное изображение на моем сервере с помощью локон и PHP, и по какой-то причине я продолжаю неудачу Может кто-то помочь ... Ниже мой кодCURL загрузки изображений PHP не работает

function download_image($image_url){ 
    $ch = curl_init($image_url); 
    // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // enable if you want 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 1000);  // some large value to allow curl to run for a long time 
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); 
    curl_setopt($ch, CURLOPT_WRITEFUNCTION, "curl_callback"); 
    curl_setopt($ch, CURLOPT_VERBOSE, true); // Enable this line to see debug prints 
    curl_exec($ch); 

    curl_close($ch);        // closing curl handle 
} 

/** callback function for curl */ 
function curl_callback($ch, $bytes){ 
    global $fp; 
    $len = fwrite($fp, $bytes); 
    // if you want, you can use any progress printing here 
    return $len; 
} 

$image_file = "ram.png"; 
$fp = fopen ($image_file, 'w+');    // open file handle 
download_image("http://chart.apis.google.com/chart?chl=30%&chs=300x120&cht=gm&chco=77AB10,FFFF00|FF0000&chd=t:30&chf=bg,s,232526"); 
fclose($fp);  
+0

Предполагается ли, что URL, чтобы URL-адрес закодированные амперсандов? – segFault

ответ

0

Возможно, для этого URL-адреса с использованием htmlspecialchars_decode поможет при использовании & в URL-адресе.

$url = htmlspecialchars_decode("http://chart.apis.google.com/chart?chl=30%&chs=300x120&cht=gm&chco=77AB10,FFFF00|FF0000&chd=t:30&chf=bg,s,232526"); 
download_image($url); 
+0

ОК, он отлично работал –

0

Попробуйте удалить закодированные амперсандов здесь:

download_image("http://chart.apis.google.com/chart?chl=30%&chs=300x120&cht=gm&chco=77AB10,FFFF00|FF0000&chd=t:30&chf=bg,s,232526"); 

так, что он выглядит следующим образом:

download_image("http://chart.apis.google.com/chart?chl=30%&chs=300x120&cht=gm&chco=77AB10,FFFF00|FF0000&chd=t:30&chf=bg,s,232526"); 
0

этот код работает для меня просто отлично

$ch = curl_init('http://soundcheck.xyz:8000/playingart?sid=1?'.$fresh); 
      var_dump($ch); 
      $fp = fopen('/home/soundcheck/public_html/images/artwork.png', 'wb'); 
      curl_setopt($fp, CURLOPT_FRESH_CONNECT, TRUE); 
      curl_setopt($fp, CURLOPT_FORBID_REUSE, TRUE); 
      curl_setopt($ch, CURLOPT_FILE, $fp); 
      curl_setopt($ch, CURLOPT_HEADER, 0); 
      curl_exec($ch); 
      curl_close($ch); 
      fclose($fp); 
Смежные вопросы