如果我不使用此代码,则永远不会显示 Instagram 图片
If I dont use this code the instagram image is never displayed
图片只有在我使用此代码时才会显示在我的网站中...
<?php
$remoteImage = "https://scontent-frt3-2.cdninstagram.com/v/t51.2885-19/s150x150/67310557_649773548849427_4130659181743046656_n.jpg?tp=1&_nc_ht=scontent-frt3-2.cdninstagram.com&_nc_ohc=M1hegfYF3_AAX9GkTGH&edm=AAuNW_gBAAAA&ccb=7-4&oh=50ba784cd64600a025031f7fc00740c1&oe=60BAEE93&_nc_sid=498da5";
$imginfo = getimagesize($remoteImage);
header("Content-type: {$imginfo['mime']}");
readfile($remoteImage);
?>
但是如果使用这个:
<?php
$link = "https://scontent-frt3-2.cdninstagram.com/v/t51.2885-19/s150x150/67310557_649773548849427_4130659181743046656_n.jpg?tp=1&_nc_ht=scontent-frt3-2.cdninstagram.com&_nc_ohc=M1hegfYF3_AAX9GkTGH&edm=AAuNW_gBAAAA&ccb=7-4&oh=50ba784cd64600a025031f7fc00740c1&oe=60BAEE93&_nc_sid=498da5";
echo "<img src='$link'>";
?>
它显示损坏的图像,如下所示:https://i.imgur.com/ufJHy1n.png,它只发生在 Instagram 图片上,因为 url 的结尾不像 xxxx.jpg
请帮忙!
如果您使用浏览器的控制台实际调试了整个过程,您就会得到答案。
关于您的变体:
- 正在将实际图像下载到您的服务器并输出二进制内容。
- 正在使用
img
标签嵌入图片,因此客户端会直接从Instagram的CDN请求图片。
变体 2) 不起作用的原因很简单:
我将在这里引用 Chrome 的开发工具:
To use this resource from a different origin, the server may relax the
cross-origin resource policy response header:
Cross-Origin-Resource-Policy: same-site
Choose this option if the
resource and the document are served from the same site.
Cross-Origin-Resource-Policy: cross-origin
Only choose this option if
an arbitrary website including this resource does not impose a
security risk.
并且 Instagram 的 CDN 策略设置为 cross-origin-resource-policy: same-origin
- 拒绝来自其他来源的请求。有关更多信息,请参见 here.
可以找到有关 Origin 的示例(即方案 + 主机 + 端口)here。
图片只有在我使用此代码时才会显示在我的网站中...
<?php
$remoteImage = "https://scontent-frt3-2.cdninstagram.com/v/t51.2885-19/s150x150/67310557_649773548849427_4130659181743046656_n.jpg?tp=1&_nc_ht=scontent-frt3-2.cdninstagram.com&_nc_ohc=M1hegfYF3_AAX9GkTGH&edm=AAuNW_gBAAAA&ccb=7-4&oh=50ba784cd64600a025031f7fc00740c1&oe=60BAEE93&_nc_sid=498da5";
$imginfo = getimagesize($remoteImage);
header("Content-type: {$imginfo['mime']}");
readfile($remoteImage);
?>
但是如果使用这个:
<?php
$link = "https://scontent-frt3-2.cdninstagram.com/v/t51.2885-19/s150x150/67310557_649773548849427_4130659181743046656_n.jpg?tp=1&_nc_ht=scontent-frt3-2.cdninstagram.com&_nc_ohc=M1hegfYF3_AAX9GkTGH&edm=AAuNW_gBAAAA&ccb=7-4&oh=50ba784cd64600a025031f7fc00740c1&oe=60BAEE93&_nc_sid=498da5";
echo "<img src='$link'>";
?>
它显示损坏的图像,如下所示:https://i.imgur.com/ufJHy1n.png,它只发生在 Instagram 图片上,因为 url 的结尾不像 xxxx.jpg 请帮忙!
如果您使用浏览器的控制台实际调试了整个过程,您就会得到答案。
关于您的变体:
- 正在将实际图像下载到您的服务器并输出二进制内容。
- 正在使用
img
标签嵌入图片,因此客户端会直接从Instagram的CDN请求图片。
变体 2) 不起作用的原因很简单:
我将在这里引用 Chrome 的开发工具:
To use this resource from a different origin, the server may relax the cross-origin resource policy response header:
Cross-Origin-Resource-Policy: same-site
Choose this option if the resource and the document are served from the same site.Cross-Origin-Resource-Policy: cross-origin
Only choose this option if an arbitrary website including this resource does not impose a security risk.
并且 Instagram 的 CDN 策略设置为 cross-origin-resource-policy: same-origin
- 拒绝来自其他来源的请求。有关更多信息,请参见 here.
可以找到有关 Origin 的示例(即方案 + 主机 + 端口)here。