【问题标题】:How to return an image from own PHP page using other server url如何使用其他服务器 url 从自己的 PHP 页面返回图像
【发布时间】:2013-11-22 12:08:50
【问题描述】:

如何制作一个 PHP 页面,该页面将从变量中 url 指定的其他服务器返回图像,如下所示:

http://www.mypage.com/MyScript.php?src=http://www.otherpage.com/image.png

进入该页面后,应该会出现一张图片。

它也需要适用于任何其他 src。

(为什么这样? 我想通过使用http://www.mypage.com/MyScript.php?src=http://www.otherpage.com/image.png 作为画布中使用的图像 src 来尝试绕过使用画布中的 toDataUrl 出现的安全错误,同时使用来自不同域的图像)

【问题讨论】:

    标签: php image url return todataurl


    【解决方案1】:

    在MyScript.php中,使用$_GET['src']作为图片来源

    <img src="<? echo $_GET['src']; ?>" />
    

    【讨论】:

      【解决方案2】:

      你可以试试

      echo file_get_contents($_GET['src']);
      

      【讨论】:

      • 只要启用了 fopen 包装器。
      • 使用任何 img url 显示错误:警告:file_get_contents() [function.file-get-contents]:第 2 行 /xxxx/xxxx/public_html/xxxx/Myscript.php 中的文件名不能为空(第 2 行是这段代码)
      • $_GET['src'] 是空的,恕我直言。尝试 print_r($_GET['src']) 检查它是否为空。或者尝试 echo file_get_contents('URL/TO/IMAGE.png') 并测试 file_get_contents 是否有效。
      猜你喜欢
      • 2012-02-23
      • 1970-01-01
      • 2019-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-02
      • 1970-01-01
      • 2012-04-24
      相关资源
      最近更新 更多