【问题标题】:Need to change the server address of the image需要更改图片的服务器地址
【发布时间】:2014-12-22 16:52:22
【问题描述】:

我有一个提供附属图片的网站:

  <img src="http://www.affiliatesite.com/immages/0001.jpg" alt="" />
  <img src="http://www.affiliatesite.com/immages/0002.jpg" alt="" />
  <img src="http://www.affiliatesite.com/immages/0003.jpg" alt="" />, etc.

我想像在我的服务器上一样显示此图像。

  <img src="http://www.mywebsite.com/images/0001.jpg" alt="" />
  <img src="http://www.mywebsite.com/images/0002.jpg" alt="" />
  <img src="http://www.mywebsite.com/images/0003.jpg" alt="" />, etc.

我不想在服务器上下载它。服务器是共享的,因此它受到限制。

知道如何做到这一点吗? 访问? php?还是两者兼有?:)

我需要的例子是

    function showimage ($img)
   {   
    header ("Content-type: image/gif"); 
    $fl = file_get_contents ("$img");
    print $fl;
    }  

只有我的服务器不允许我这样做...

【问题讨论】:

  • str_replace("http://www.affiliatesite.com/immages", "http://www.mywebsite.com/images" , $File) 也许?
  • 您到底想要做什么,为什么?做你想做的唯一方法是代理图像,但你只是说你不想这样做。
  • 图像应该从远程服务器显示,但 html 中的文件路径应该看起来好像文件在我的服务器上。
  • 类似于函数 showimage ($img) { header ("Content-type: image/gif"); $fl = file_get_contents ("$img");打印 $fl; }

标签: php .htaccess


【解决方案1】:

这样的东西应该适合你:

<?php

    $file = "page.php";
    $search = "http://www.affiliatesite.com/immages";
    $replacment = "http://www.mywebsite.com/images";

    $str = file_get_contents($file);
    $str = str_replace($search, $replacment,$str);
    file_put_contents($file, $str);

?>

举个例子:

page.php 之前:

<img src="http://www.affiliatesite.com/immages/0001.jpg" alt="" />
<img src="http://www.affiliatesite.com/immages/0002.jpg" alt="" />
<img src="http://www.affiliatesite.com/immages/0003.jpg" alt="" />

page.php 在脚本之后:

<img src="http://www.mywebsite.com/images/0001.jpg" alt="" />
<img src="http://www.mywebsite.com/images/0002.jpg" alt="" />
<img src="http://www.mywebsite.com/images/0003.jpg" alt="" />

【讨论】:

  • @SHCodeR 这些图像标签在一个文件中,对吧?如果是,您可以编写此脚本更改文件名并执行它!如果您可以写入文件,它将更改文件中匹配的所有字符串!
  • @SHCodeR 你需要让你的问题更清楚。在 cmets 中指出,不清楚您在问什么。
猜你喜欢
  • 1970-01-01
  • 2015-09-05
  • 1970-01-01
  • 2015-10-17
  • 2012-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多