简体   繁体   English

PHP URL转换为html img src

[英]PHP url into html img src

i'm using and url from Facebook to insert into HTML img src .. that url is not an image, this url (when opened on a browser) redirects to an image. 我正在使用来自Facebook的URL并将其插入HTML img src ..该URL不是图像,该URL(在浏览器中打开时)将重定向到图像。

 <img src="https://graph.facebook.com/274084006029120/picture?width=100" />

This image is shown correctly everywhere. 此图像在任何地方都能正确显示。

Then I build a cover.php program that only redirect to an http://../image.jpg 然后,我构建一个cover.php程序,该程序仅重定向到http://../image.jpg

Then i add on HTML source 然后我添加HTML源代码

 <img src="https://.../cover.php" />

On most browsers and emails this cover.php program Works fine and shows the picture. 在大多数浏览器和电子邮件中,这个cover.php程序可以正常工作并显示图片。 But on some components (editors) seems the php is not executed and the picture is not show. 但是在某些组件(编辑器)上,似乎未执行php并且未显示图片。

How can i solve this ? 我该如何解决? or how can i do redirect (need some code before) to work like Facebook redirect ? 或者我该如何重定向(之前需要一些代码)才能像Facebook重定向那样工作?

Thanks a lot ! 非常感谢 !

您可以通过将以下行添加到您的php代码来重定向浏览器:

header('Location: http://..../image_url');

Perhaps you can get the redirected url like in this answer 也许您可以像这样的答案中获得重定向的URL

$url = 'https://graph.facebook.com/274084006029120/picture?width=100';

file_get_contents($url);
preg_match('/(Location:|URI:)(.*?)\n/', implode("\n", $http_response_header), $matches);

if (isset($matches[0]))
{
    echo "<img src='".matches[0]."' />";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM