简体   繁体   中英

have img src = dl-main.php?f=filename.jpg retrieve said image from remote server

I am trying to do the following; dynamically pick a server with the image on it, and then show said image in img src="" . Yeah I know, I am horrible at explaining stuff like this but this should clear it up:

dl-main.php (on server0.domain.com)

$url = 'http://server2.domain.com/offerimage.php?f='.$_GET["f"];
header( 'Location: '.$url ) ;

offerimage.php (on server2.domain.com)

//Lots of link-protection stuff here
$f = "/".$_GET["f"];
$url = 'http://server2.domain.com'.$uri_prefix.$m.'/'.$t_hex.$f;
echo' <img src="'.$url.'"></img> ';

dl.php (on many other servers)

img src="http://server0.domain.com/dl-main.php?f=lalala.gif"

So it pretty much goes like this: Random person adds img src directing to dl-main.php?f= filename on server0. server0 then decides which server will provide the image. In the above example I am using only one server; server2

Now I simply want dl.php to show the photo hosted on server2.domain.com . As it stands when I directly visit dl-main.php it succesfully redirects me to dl.php, which then succesfully shows me the image I requested. But when I use dl-main.php in a img src it doesn't show the image. I didn't expect it to work but it was worth a shot, but now I don't know what to do anymore :o

I hope this failed attempt is a good example of what I'm trying to accomplish here.

Thanks!

Here's the problem. You call image from server0 using:

<img src="http://server0.whatever/dl-main.php?f=thatimage.something" />

Where the dl-main.php code redirects to server2. Here, you do:

echo' <img src="'.$url.'"></img> ';

So basically the original img tag would get another img tag instead of the image data. That's why the browser can't render the image. You should echo the content of the image instead of an img tag.

Try using your browser's developer tools and check the request to server2 to verify my guess.

它不起作用,您的第二个脚本(offerimage)正在生成text/plain ,您应该生成image/...以便使用img

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