简体   繁体   中英

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.

 <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

Then i add on HTML source

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

On most browsers and emails this cover.php program Works fine and shows the picture. But on some components (editors) seems the php is not executed and the picture is not show.

How can i solve this ? or how can i do redirect (need some code before) to work like Facebook redirect ?

Thanks a lot !

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

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

Perhaps you can get the redirected url like in this answer

$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]."' />";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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