【问题标题】:How can user download the image to their mobile gallery?用户如何将图像下载到他们的移动图库?
【发布时间】:2012-10-25 11:46:43
【问题描述】:

这是我的代码,

<?php
$file_name = "coupon.png";
$file_path = $_GET['path'];
$file_size = filesize($file_path);
header('Pragma: public');
header('Expires: 0');
header('Last-Modified: ' . gmdate('D, d M Y H:i ') . ' GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $file_size);
header('Content-Disposition: attachment; filename="' . $file_name . '";');
header('Content-Transfer-Encoding: binary');
readfile($file_path);
?>

附: $_GET['path'] 图片路径 url

在PC的浏览器中,那些编码可以流畅运行。 但是,如果用户使用他们的移动浏览器下载,它将显示一个新的网页标签。

用户有什么方法可以自动下载图片并存储到他们的手机图库中?

【问题讨论】:

    标签: php mobile safari mobile-website


    【解决方案1】:

    试试这样:

    <?php
    $file_name = "coupon.png";
    $file_path = $_GET['path'];
    $file_size = filesize($file_path);
    header('Pragma: public');
    header('Expires: 0');
    header('Last-Modified: ' . gmdate('D, d M Y H:i ') . ' GMT');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Cache-Control: private', false);
    header('Content-Type: application/force-download'); // Browser cant identifiy the type. so it will force to download
    header('Content-Length: ' . $file_size);
    header('Content-Disposition: attachment; filename="' . $file_name . '";');
    header('Content-Transfer-Encoding: binary');
    readfile($file_path);
    ?>
    

    因为手机浏览器不知道怎么打开文件,所以强制下载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      相关资源
      最近更新 更多