1

私のブラウザでは、すべての形式、zip、kml、pdf をダウンロードできますが、iPhone または iPad から試してみると、zip と kml では機能しますが、pdf では機能しません。誰かが私が間違ったことを指摘してもらえますか? 私が使用しているコードは次のとおりです。

<?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);    
?>

また、私が使用してみたことに注意したいと思います

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

それはアップルのデバイスでも機能しませんでした。

助けていただければ幸いです。

4

1 に答える 1

1

インラインで試しましたか:

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

これをテストしたところ、iPad で問題なく動作しました。結構、それが表示されるということです。ここで何が起こると期待しているかを正確に説明していません。

于 2012-11-29T22:33:31.790 に答える