iphone jquery-mobile 下载图片

标签 iphone image jquery-mobile download

我在 jquery-mobile 上有移动网站,它显示图库。有一个按钮,单击时应该下载当前图像。 它使用小型服务器端 php 脚本在 Android 和桌面浏览器中运行良好。 但在 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;
   }); 

关于iphone jquery-mobile 下载图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16961407/

相关文章:

iphone - "EXC_BAD_ACCESS", "-[CFString retain]: message sent to deallocated instance"在表格中滚动时

javascript - onclick 阻止在 Mobile Safari 上复制+粘贴?

html - 如何在我的应用程序中嵌入图像并在 HTML 控件中使用它们?

php - 在使用 imagecache_create_path & getimagesize 之前使用 Drupal imagecache 生成图像

php - 难题 - 如何从 PHP 中提取图像的 'colorify' 部分?

javascript - 滚动不适用于动态添加到 jQuery 移动列表的项目

javascript - jQuery show()/hide() 在 iPhone/Android 上工作吗?

ios - NSOperation 在后台任务结束之前完成

jquery-mobile - 使用 jQuery Mobile 控制硬件后退按钮

javascript - 如何制作可折叠菜单 jQuery Mobile