Ron
Ron

Reputation: 23

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 image 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!

Upvotes: 2

Views: 1209

Answers (2)

Vvouter
Vvouter

Reputation: 1

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..

Upvotes: 0

Yoshi
Yoshi

Reputation: 54649

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%");

Upvotes: 4

Related Questions