开发者

Pass through image from URL on dynamic script

Is it possible to pass through an image file from a remote URL, without downloading it to the local server?

I have a PHP script that tracks stats and then outputs an ima开发者_StackOverflow社区ge via readfile(). Example:

<img src="http://example.com/image.php?img=1234">

I'd like to use a CDN to reduce load, and take advantage of geo-location services to serve images faster. So, the script needs to output the image straight from the CDN and not download it to the local server for output.

Any advice on how to achieve this? Is it possible? Thanks in advance!


Do your tracking, but send the browser to the real location afterwards.

See: http://php.net/manual/en/function.header.php

<?php
header("HTTP/1.0 303 See Other");
header("Location: %the real uri%");


If you know the name and the location of the image on the remote server you can just use their webspace and only pass through the imagename.

Then in your code you hardcode the imagepath and give the imagename as a dynamic parameter..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜