我有一张图片的下方网址。它的分辨率约为1500px宽度和300kb。 我通过ajax将url发送到服务器并尝试保存。但它节省了一半的图像。像腐败一样。
图片网址:
$url = "https://textronic.online/WEB_API_TDS/v1/img?part=SHSLIM&swatch=F1A0F99B/part=9038004B&swatch=F1A0F99B/part=7FEA98C3&pair=9038004B&swatch=F1A0F99B&pair=9038004B/part=BTBLACK&pair=9038004B&swatch=F1A0F99B&pair=9038004B/part=BHBLACK&pair=9038004B&swatch=F1A0F99B&pair=9038004B/part=EA8BD88C&swatch=F1A0F99B/part=7FEA98C3&pair=EA8BD88C&swatch=F1A0F99B&pair=EA8BD88C/part=BTBLACK&pair=EA8BD88C&swatch=F1A0F99B&pair=EA8BD88C/part=BHBLACK&pair=EA8BD88C&swatch=F1A0F99B&pair=EA8BD88C/part=E339C530&swatch=F1A0F99B/part=7FEA98C3&pair=E339C530&swatch=F1A0F99B&pair=E339C530/part=BTBLACK&pair=E339C530&swatch=F1A0F99B&pair=E339C530/part=BHBLACK&pair=E339C530&swatch=F1A0F99B&pair=E339C530/part=B5CB81BC&swatch=F1A0F99B/part=7FEA98C3&pair=B5CB81BC&swatch=F1A0F99B&pair=B5CB81BC/part=BTBLACK&pair=B5CB81BC&swatch=F1A0F99B&pair=B5CB81BC/part=BHBLACK&pair=B5CB81BC&swatch=F1A0F99B&pair=B5CB81BC/part=REGULARBOTTOM&swatch=F1A0F99B/part=7FEA98C3&swatch=F1A0F99B/part=DIAMOND&swatch=F1A0F99B/part=BOXPLEAT&swatch=F1A0F99B/part=EPNO&swatch=F1A0F99B/part=BHBLACK&swatch=F1A0F99B/part=BTBLACK&swatch=F1A0F99B/view=face";
方法-1
$contents=file_get_contents($url);
$save_path="dimage.jpg";
file_put_contents($save_path,$contents);
结果:图片应为红色。但它是白色的。原因尚未完全保存。
方式-2
copy($url, 'image2.jpg');
结果:图片应为红色。但它是白色的。原因尚未完全保存。
方式-3 卷曲方法。这没用。保存了0kb图像。
方式-4
header("content-type: image/jpg");
$qr_image = imagecreatefrompng($url);
$save = getcwd()."image4.jpg";
imagejpeg($qr_image,$save); //save the file to $save path
imagejpeg($qr_image); //display the image
结果已损坏。
基本上尝试了以下帖子方法:PHP - Copy image to my server direct from URL
如果有人有解决方案,请在此处回答。
谢谢
答案 0 :(得分:2)
content-length:
个字节数之前随机关闭连接。我跑了10次这个命令
curl -v 'https://textronic.online/WEB_API_TDS/v1/img?part=SHSLIM&swatch=F1A0F99B/part=9038004B&swatch=F1A0F99B/part=7FEA98C3&pair=9038004B&swatch=F1A0F99B&pair=9038004B/part=BTBLACK&pair=9038004B&swatch=F1A0F99B&pair=9038004B/part=BHBLACK&pair=9038004B&swatch=F1A0F99B&pair=9038004B/part=EA8BD88C&swatch=F1A0F99B/part=7FEA98C3&pair=EA8BD88C&swatch=F1A0F99B&pair=EA8BD88C/part=BTBLACK&pair=EA8BD88C&swatch=F1A0F99B&pair=EA8BD88C/part=BHBLACK&pair=EA8BD88C&swatch=F1A0F99B&pair=EA8BD88C/part=E339C530&swatch=F1A0F99B/part=7FEA98C3&pair=E339C530&swatch=F1A0F99B&pair=E339C530/part=BTBLACK&pair=E339C530&swatch=F1A0F99B&pair=E339C530/part=BHBLACK&pair=E339C530&swatch=F1A0F99B&pair=E339C530/part=B5CB81BC&swatch=F1A0F99B/part=7FEA98C3&pair=B5CB81BC&swatch=F1A0F99B&pair=B5CB81BC/part=BTBLACK&pair=B5CB81BC&swatch=F1A0F99B&pair=B5CB81BC/part=BHBLACK&pair=B5CB81BC&swatch=F1A0F99B&pair=B5CB81BC/part=REGULARBOTTOM&swatch=F1A0F99B/part=7FEA98C3&swatch=F1A0F99B/part=DIAMOND&swatch=F1A0F99B/part=BOXPLEAT&swatch=F1A0F99B/part=EPNO&swatch=F1A0F99B/part=BHBLACK&swatch=F1A0F99B/part=BTBLACK&swatch=F1A0F99B/view=face'
并且在2/10次尝试中,curl抱怨连接过早关闭...联系textronic.online
开发人员让他们知道,他们的http / 2服务器代码似乎有问题。直到他们修复它,使用
curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
使用curl强制下载http / 1.1,而不是http / 2 - 这相当于将-http1.1添加到curl命令行,这似乎使下载稳定。
(ps,不知道为什么有这么多人贬低你,可能是坏的部分被编辑掉了?)