显示图像形式其他服务器和浏览器上的路径显示应该是我的服务器

时间:2010-01-05 07:44:24

标签: php apache apache-config

我想显示其他网站的一些图片,但我想要自己的服务器网址,而不是存储在我的最后。

代码中的

我写得像这样

<img src="http://image.com/ab.gif"/>

但是在bowser源显示为

<img src="http://mysite.com/ab.gif"/>

4 个答案:

答案 0 :(得分:1)

您可以重定向脚本:

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

其中lookup()是您编写的函数,用于从数据库或平面文件或其他任何内容中查找URL。假设该脚本名为image.php,那么您的URL将如下所示:

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

其中kitten1234是图片ID。

您甚至可以使用mod_rewrite重写URL并删除image.php部分。

答案 1 :(得分:1)

不是PHP答案,但是如果你运行带有mod_rewrite和mod_proxy的Apache,你可以在一个服务器之间建立一个软件链接到另一个服务器。 将其插入.htaccess文件:

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

调用http://yourhost/somepath/kittens.jpg实际上会显示http://otherhost/otherpath/kittens.jpg而不会泄露原始地址。

答案 2 :(得分:0)

您可以在Apache中使用mod_rewrite:

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

这会将http://yoursite/images/anyimage.jpg的所有请求重定向到http://anothersite/images/anyimage.jpg

答案 3 :(得分:-1)

嗯,你可以这样做:

<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")); ?>" />

这将获取图像并将其显示为内嵌数据,它将不会作为URL提供,但它将在您的网站上(如果您要禁用显示原始网址)。

您可以做的其他事情是使用mod_rewrite强制每个图像查找到php脚本。 在该脚本中,您可以拥有一组图像(或查询数据库)以获取原始图像URL并使用php显示它。这有点复杂,需要您为网站上的每张图片输入原始图片网址。