1

In my browser i can download all formats, zip, kml, pdfs, But when i try from a iphone or ipad it will work for the zips and kmls but not for the pdf. Can someone please point out what I've done incorrectly? the code I'm using is:

<?php
    $file = "/raid0/data/naswebsite/Projects/Projects/" . $_GET["file"];
    $parts = explode('/', $file);
    $download = $parts[count($parts) - 1];

    if (!file_exists($file))
    {
        echo "The file $file does not exist on the server.";
        exit;
    }

    if (strpos(strtolower($file), ".zip"))
    {   
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=' .urlencode($download));
        header('Content-Transfer-Encoding: binary');
    }
    else if (strpos(strtolower($file), ".pdf"))
    {   
        header('Content-Type: application/vnd.adobe.pdf');
        header('Content-Disposition: attachment; filename=' .urlencode($download));
        header('Content-Transfer-Encoding: binary');
    }
    else if (strpos(strtolower($file), ".kml"))
    {   
        header('Content-Type: application/vnd.google-earth.kml+xml');
        header('Content-Disposition: attachment; filename=' .urlencode($download));
        header('Content-Transfer-Encoding: binary');
    }
    else
    {
        header('Content-Type: application/text');
        header('Content-Disposition: attachment; filename=' .urlencode($download));
        header('Content-Transfer-Encoding: binary');        
    }

    readfile($file);    
?>

I will also like to note I've tried using

header('Content-Type: application/pdf');

that also didn't work on the apple devices.

help appreciated.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Dean
  • 499
  • 6
  • 13
  • 34
  • What do you mean by "it doesn't work"? Some browsers will render PDFs on their own. – Brad Nov 29 '12 at 22:28
  • Have you tried this answer http://stackoverflow.com/questions/364946/how-to-make-pdf-file-downloadable-in-html-link ? – tftd Nov 29 '12 at 22:31
  • It won't open the pdf content types in iphone/ipad/safari, I was wondering what was wrong with my code, All other files open in the browser, just not the pdfs. – Dean Nov 29 '12 at 22:31

1 Answers1

1

Have you tried inline:

header('Content-disposition: inline; filename=' .urlencode($download));
header('Content-type: application/pdf');

I tested this and it works fine on my ipad. By fine, I mean it displays it. You don't exactly describe what you're expecting to happen here.

Kai Qing
  • 18,793
  • 5
  • 39
  • 57
  • 1
    tried, this didn't solve my problem.im calling fetcher.php from ajax and displaying it inside a iframe that's hidden. dunno why it wont work for just pdfs, works for everything else i try. – Dean Nov 30 '12 at 00:43