用cURL php抓取图像

Dav*_*rin 2 php upload curl image save

尝试使用cURL将图像保存到我的服务器.图像似乎下载.它显示正确的字节,但当我链接图像不起作用.我然后DL看到并且没有它的空白图像.

这是我的代码...问题是什么?

$ch = curl_init("'. $image .'");
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);

$fp = fopen("$rename.jpg",'w');
fwrite($fp, $rawdata); 
fclose($fp);
Run Code Online (Sandbox Code Playgroud)

小智 7

我测试你的脚本它对我来说很好,只需删除无用的双引号和$ image图像.

<?
$image ="http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=5";
$rename="123";

$ch = curl_init($image);
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);

$fp = fopen("$rename.jpg",'w');
fwrite($fp, $rawdata); 
fclose($fp);
?>
Run Code Online (Sandbox Code Playgroud)