2

我在 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');

}
?>
4

1 回答 1

1

我知道这有点晚了,但是把这个脚本放在 jQuery Mobile 之前它对我有用:

 $(document).bind("mobileinit", function(){
          $.mobile.ajaxEnabled = false;
   }); 
于 2013-09-24T22:01:45.960 回答