【问题标题】:Page content type页面内容类型
【发布时间】:2011-04-16 22:54:39
【问题描述】:

我有一个指向图片的页面链接列表。当我单击某些图像在浏览器中打开时,我需要使其可下载(使用必须查看图像保存窗口)。据我所知,我必须制作脚本(仅限 php),并在链接地址中使用它,并将图像名称传递给它。然后,以某种方式更改内容类型页面并要求用户下载文件。 你能帮我写这个脚本吗?

【问题讨论】:

    标签: php image download types


    【解决方案1】:

    来自PHP.net

    <?php
    $file = 'monkey.gif';
    
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 2011-09-12
      • 1970-01-01
      相关资源
      最近更新 更多