我想显示来自其他站点的一些图像,但我想要我自己的服务器 url 而不是存储在我的末尾。
在我这样写的代码中
<img src="http://image.com/ab.gif"/>
但在鲍泽源显示为
<img src="http://mysite.com/ab.gif"/>
我想显示来自其他站点的一些图像,但我想要我自己的服务器 url 而不是存储在我的末尾。
在我这样写的代码中
<img src="http://image.com/ab.gif"/>
但在鲍泽源显示为
<img src="http://mysite.com/ab.gif"/>
你可以让你的脚本重定向:
<?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 部分。
不是 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而不会显示原始地址。
您可以在 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。
那么你可以这样做:
<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 提供,但会在您的站点上(如果您想禁用显示原始 URL-s)。
您可以做的另一件事是使用 mod_rewrite 强制每个图像查找到一个 php 脚本。在该脚本中,您可以拥有一组图像(或查询数据库)以获取原始图像 url 并使用 php.ini 显示它。这有点复杂,需要您为网站上的每张图片输入原始图片 URL。