원격 사이트의 이미지를 저장해야합니다. 내 호스트는 file_get_contents를 허용하지 않으므로 컬을 시도하고 있습니다. 코드로 이미지를 수집하고 있습니다. 도와주세요!PHP의 원격 서버에서 이미지 저장
$destination = realpath("../../app/webroot/img/uploads") . "/" . $facebook_id . "." . "gif";
// Delete previous pic
if (file_exists($destination)) {
unlink($destination);
}
// Save new pic
$remoteUrl = "https://graph.facebook.com/" . $facebook_id . "/picture";
$ch = curl_init($remoteUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$rawdata = curl_exec($ch);
curl_close($ch);
$fp = fopen($destination, 'w');
fwrite($fp, $rawdata);
fclose($fp);
당신이 손상된 데이터를 보았다? 그것은 부분적인 이미지입니까? 길이가 0 인 파일? '$ rawdata'가 실제로 boolean인지 확인 했습니까? false로 말하면 어떻게 든 실패 했습니까? –
페이스 북으로 일한 경험이 없으십니까? –
@MarcB $ rawdata가 비어 있습니다. – user1871640