【发布时间】:2018-04-07 19:19:53
【问题描述】:
我有一张图片的以下网址。它的分辨率约为 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);
结果:图像应为红色。但它是白色的。原因未完全保存。
方法二
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
如果有人有解决方案,请在这里回答。
谢谢
【问题讨论】:
-
4k 代表,你问这样的问题???
-
是的,尝试了 4 种不同的方法。没有成功。
-
要在服务器上保存图像,您需要文件上传而不是通过 ajax 发送链接
-
@Ferhad Othman:尝试使用 file_get_contents、curl、copy..methods。仅工作复制功能。图像保存了一半。尝试使用小图像并且在不上传图像的情况下使用复制功能效果很好。
-
@apokryfos:为您的反对票添加了尝试过的代码。