【问题标题】:image button "save as" to save file from external servers php script图像按钮“另存为”从外部服务器 php 脚本保存文件
【发布时间】:2012-02-04 16:26:43
【问题描述】:

我的服务器上有一个图片库。图片存储在不同的外部服务器上。在我的服务器上仅放置缩略图。 我如何在 php 中创建一个“另存为”按钮,以便用户可以下载来自外部服务器的大图片文件。我需要一个简单的 php 脚本,它可以跨所有浏览器代理和不同的外部服务器下载 jpg 文件。该按钮将在 html 代码中实现。该按钮是以 css 样式格式的常规链接。 那么如何正确地做到这一点。谢谢。

我还希望文件的路径应该以某种方式作为可变参数发送到 php 脚本。

【问题讨论】:

  • 为什么不把用户链接到原始的全尺寸图片?
  • 因为我不希望那个用户看到文件 url 地址。

标签: php image button download external


【解决方案1】:

删除文件名中的空格:

更改: http://backalleypics.com/Pictures/Letter Je~Ju/Jessica Alba/Jessica Alba 230.jpg

收件人: http://backalleypics.com/Pictures/Letter_Je~Ju/Jessica_Alba/Jessica_Alba_230.jpg

【讨论】:

    【解决方案2】:

    我用下面的 php 脚本找到了一些解决方案

    <?PHP
     // Define the path to file
     $file = $_GET['file'];
     $name = basename ($file);
     if(!file)
     {
     // File doesn't exist, output error
     die('file not found');
     }
     else
     {
     // Set headers
     header("Cache-Control: public");
     header("Content-Description: File Transfer");
     header("Content-Disposition: attachment; filename=$name");
     header("Content-Type: image/jpg");
     header("Content-Transfer-Encoding: binary");
    
     // Read the file from disk
     readfile($file);
     }
     ?>
    

    我可以发送参数,如url地址跨html代码

    <a href="download.php?file=http://someserver/picture.jpg">download</a>
    

    唯一的问题是它不适用于所有服务器。以该文件为例,它不起作用

    http://backalleypics.com/Pictures/Letter Je~Ju/Jessica Alba/Jessica Alba 230.jpg
    

    我不知道我需要做什么?

    【讨论】:

    • 我注意到我发送跨html代码的url地址时出现问题。当地址包含在 php 脚本中时 $file = "backalleypics.com/Pictures/Letter Je~Ju/Jessica Alba/Jessica Alba 230.jpg";一切正常。但我只想发送 url 交叉 html 代码。我怎样才能毫无问题地做到这一点?
    【解决方案3】:

    我猜您正在尝试自动下载图片(您希望弹出一个对话框提示保存文件的位置)。

    这个网站上有一个很棒的教程使用php header function to force download

    查看:http://www.ryboe.com/tutorials/php-headers-force-download

    【讨论】:

    • 没错我就是要弹出一个对话框提示保存文件的位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 2019-03-19
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多