我在jquery-mobile上有移动站点,它显示画廊。有一个按钮,当点击它应该下载当前图像。它在android和桌面浏览器中运行良好,使用小的服务器端php脚本。但在iphone中,它只是在新标签页中打开图像。是的,我知道,你可以很容易地通过长按下载图像,但是。我不是那个想要这样的人)
脚本:
<?php
$file = $_GET['f'];
$file = "images/com_product/product/large/".$file;
download_file($file);
function download_file( $fullPath ){
// Must be fresh start
if( headers_sent() )
die('Headers Sent');
// Required for some browsers
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
// File Exists?
if( file_exists($fullPath) ){
// Parse Info / Get Extension
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
// Determine Content Type
switch ($ext) {
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename="".basename($fullPath)."";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
ob_clean();
flush();
readfile( $fullPath );
} else
die('File Not Found');
}
?>
我知道这有点晚了,但是把这个脚本放在jQuery Mobile之前,它为我工作:
$(document).bind("mobileinit", function(){
$.mobile.ajaxEnabled = false;
});