使用PHP Curl或文件获取内容下载Instagram图像

使用PHP Curl或文件获取内容下载Instagram图像,php,curl,instagram,Php,Curl,Instagram,我有这个图片,我正试图下载 https://www.instagram.com/p/CHZGLObDQV2/media/?size=l 所有Instagram图像的问题在于,当您单击该URL时,它会将您重定向到原始URL,即: https://instagram.fcrk2-1.fna.fbcdn.net/v/t51.2885-15/e35/s1080x1080/124374363_458291788482210_6691254472190084475_n.jpg?_nc_ht=instagra

我有这个图片,我正试图下载
https://www.instagram.com/p/CHZGLObDQV2/media/?size=l
所有Instagram图像的问题在于,当您单击该URL时,它会将您重定向到原始URL,即:

https://instagram.fcrk2-1.fna.fbcdn.net/v/t51.2885-15/e35/s1080x1080/124374363_458291788482210_6691254472190084475_n.jpg?_nc_ht=instagram.fcrk2-1.fna.fbcdn.net&_nc_cat=106&_nc_ohc=VuSNajTRd78AX_GZlsF&_nc_tp=15&oh=cc224ca1041c97c06ec124a98e0241ca&oe=5FD536C4
如何使用
curl
file\u get\u contents
下载Instagram的原始URL

我有以下代码:

$url = "https://www.instagram.com/p/CHZGLObDQV2/media/?size=l";

save_image($url,"/test/images/test.jpg");

function save_image($img,$fullpath){
 $ch = curl_init ($img);
 curl_setopt($ch, CURLOPT_HEADER, 1);
 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);
}
此文件无法正确保存,因为它无法获取原始URL


非常感谢你的帮助!谢谢大家!

@StackSlave-当我使用邮递员访问它时,我得到了它,但当通过web浏览器时,我被重定向到原始图像URL。您是否尝试过将其访问到web浏览器中?我尝试过大型URL,如:
header('Content-Description:filetransfer');标题(“内容类型:应用程序/八位字节流”);标题('Content-Disposition:attachment;filename=“”.basename($url)。“”);标题('Expires:0');标头(“缓存控制:必须重新验证”);标题(“Pragma:public”);标题('Content-Length:'.filesize($url));readfile($url);死亡却一无所获。除非你在他们的服务器上,否则他们一定会阻止你看到它。嘿,有人对此有任何答案吗