用户如何将图像下载到他们的移动图库?

时间:2012-10-25 11:46:44

标签: php mobile safari mobile-website

这是我的代码,

<?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);
?>

P.S。 $_GET['path']用于图片路径网址

在PC的浏览器中,那些编码可以顺利运行。 但是,如果用户使用他们的移动浏览器进行下载,它将显示一个新的网页选项卡。

用户是否可以自动下载图片并存储到他们的移动图库中?

1 个答案:

答案 0 :(得分:0)

试试这样:

<?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);
?>

因为移动浏览器不知道如何打开文件,所以不得不下载。