views:

114

answers:

4

I want to show some images from other sites but i want my own servers url without storing at my end.

in code i write like this

<img src="http://image.com/ab.gif"/&gt;

but on bowser source display as

<img src="http://mysite.com/ab.gif"/&gt;
+1  A: 

You could have your script redirect:

<?php
$image = $_POST['image'];
$url = lookup($image);
header('Location: ' . $url);
exit;

where lookup() is a function you write to look up the URL from the database or a flat file or whatever. Assuming the script is called image.php then your URLs will look like:

http://yourdomainname.com/image.php?image=kitten1234

where kitten1234 is the image ID.

You could even use mod_rewrite to rewrite the URL and remove the image.php part.

cletus
+1  A: 

Not a PHP answer but if you run Apache with mod_rewrite and mod_proxy activated, you can make a sort of soft link of a folder from one server to the other. Plug this in an .htaccess file:

RewriteEngine on
^/somepath(.*) http://otherhost/otherpath$1 [P]

Calling http://yourhost/somepath/kittens.jpg will actually show http://otherhost/otherpath/kittens.jpg without revealing the original address.

w00kie
I want to do it in php code, thanks for your assistance
uwillneverknow
A: 

Well you could do this:

<img src="data:image/gif;base64,<?php echo base64_encode(file_get_contents("http://www.qweas.com/downloads/graphic/animation-tools/scr-coffeecup-gif-animator.gif")); ?>" />

This will get the image and display it as inline data, it will not be available as an URL but it will be on your site (if you want to to disable showing original URL-s).

Other thing you could do is to force every image lookup to a php script with mod_rewrite. In that script you could have an array of images (or query the database) for original image url and display it with php. This is a bit complicated and will require you to enter original image URL for every image you have on a site.

dfilkovi
this will not work in IE
Hippo
Why -1? It works in IE, not in older versions 5 and 6. And also there is another option I specified.
dfilkovi
A: 

You can use a mod_rewrite in Apache:

RewriteEngine On # Turn on the rewriting engine
# Redirect requests for images/* to images/* on anothersite
RewriteRule ^images/(.+)/?$ http://anothersite/images/$1 [NC,L]

This will redirect all requests for http://yoursite/images/anyimage.jpg to http://anothersite/images/anyimage.jpg.

Chaim Chaikin