Comment télécharger une image externe d'une URL avec cURL?Téléchargement d'une image à partir d'une URL externe avec cURL
1
A
Répondre
1
Voir ici:
http://www.edmondscommerce.co.uk/php/php-save-images-using-curl/
function save_image($img,$fullpath){
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath,'x');
fwrite($fp, $rawdata);
fclose($fp);
}
Autres articles/sources:
http://forums.digitalpoint.com/showthread.php?t=371632
0
de php.net - se lit également dans une chaîne.
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "example.com");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
?>
http://stackoverflow.com/questions/1898711/use-curl-to-download-indirect-image-file – DampeS8N
Toute raison pour laquelle choisiriez-vous cURL sur file_get_contents()? –
Je ne suis pas sûr que fopen sera activé sur mon serveur, donc j'évite d'utiliser file_get_contents(). – moteutsch