【问题标题】:iphone jquery-mobile download imageiphone jquery-mobile 下载图片
【发布时间】:2013-06-06 11:51:52
【问题描述】:

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

}
?>

【问题讨论】:

  • 我的第一个猜测,iOS 不支持这个。由于它没有公共文件系统,safari 只会显示已知的文件类型。未知的文件类型将什么都不做。

标签: iphone image jquery-mobile download


【解决方案1】:

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

 $(document).bind("mobileinit", function(){
          $.mobile.ajaxEnabled = false;
   }); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 2012-05-23
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多