title: iphone jquery-mobile download image
body: <p>I have mobile site on jquery-mobile, which display gallery. There is button, when clicked it should download current image. 
  It is working fine in android and desktop browser, using small server-side php script.
  But in iphone it simply open's image in the new tab. Yeah, I know, you can easily download image simply by long-tapping, but well. I'm not the one who want this) </p>
  
  <p>Script:</p>
  
  <pre><code>&lt;?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');
  
  }
  ?&gt;
  </code></pre>