LoginSignup
3
1

More than 5 years have passed since last update.

MacOS safariブラウザでダウンロードコンテンツが欠損する件

Last updated at Posted at 2018-06-29
ok.php

    header("HTTP/1.1 200 OK", true, 200);
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"{$todayTimestamp}.pdf\"");
    readfile(DOCUMENT_DIR."/".$documentType);

結論としては上記コードが正常動作した.

不具合のあったソースは

ng.php
    $documentBinary = file_get_contents(DOCUMENT_DIR."/".$documentType);
    header("HTTP/1.1 200 OK", true, 200);
    header("Content-Type: application/pdf");
    header("Content-Length: ".strlen($documentBinary));
    header("Content-Disposition: attachment; filename=\"{$todayTimestamp}.pdf\"");
    print($documentBinary);

だった.

//以下ソースをコメントアウト
//header("Content-Length: ".strlen($data));
// file_get_contents($path);をやめて
readline($path);

これでうごきました.

ng.phpのソースでもwindows上の各種ブラウザでは問題なく動作しておりましたが
MacOS上のsafariでは全く動作しないどころかダウンロードしたファイルがなにかしらの欠損が発生していたようです.

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1