[PHP-users 29146] Re: PDF ・ MS Office ファイルなどをダウンロードする方法

こやま puyoumailaddress @ yahoo.co.jp
2006年 5月 8日 (月) 20:24:40 JST


鈴木様 アドバイスありがとうございます。

> 1.
> $pdffile = 'dokokano/pdf/file.pdf';
> header("Content-length: " . filesize($pdffile));
> header("Content-type: application/pdf");
> header("Content-Disposition: inline; filename=tekitou");
> readfile($pdffile);

> 2.
> php.iniの設定で出力のバッファリングが有効になっている
> PDFファイルの送信前に、ob_end_flush()とやるのが私の定法です。

いただいた上記の情報をもとに、試してみたのですが「%PDF...」が表示
されてしまいます。異なるのは、試す前は入っていなかった改行コードが
入ってくるようになった点です。
php.ini の設定で、原因となりそうな箇所はありますでしょうか?

私の行った手順は以下です。
1. hoge2.phpの変更
----- hoge2.php ここから
  ob_start();
  $fname = 'test.pdf';
  $path_file = '/var/www-ssl/doc/' . $fname;
  /* ファイルの存在確認 */
  if( !file_exists( $path_file )){
    ob_end_clean();
    die("Error: File does not exist.");
  }
  /* オープンできるか確認 */
  if( !($fp = fopen( $path_file, "r" ))){
    ob_end_clean();
    die("Error: Cannot open the file(".$path_file.")");
  }
  fclose($fp);
  /* ファイルサイズの確認 */
  if(( $content_length = filesize( $path_file )) == 0 ){
    ob_end_clean();
    die("Error: File size is 0.");
  }
  /* ダウンロード用のHTTPヘッダ送信 */
  header("Content-Length: " . filesize($path_file));
  header("Content-Type: application/pdf");
  header("Content-Disposition: inline; filename=test" );
  /* ファイルを読んで出力 */
  if( !readfile( $path_file )){
    ob_end_clean();
    die("Cannot read the file(".$path_file.")");
  }
  ob_end_flush();
----- ここまで
2. php.iniの変更
   output_buffering = Off → 4096に変更
   memory_limitは最初に変更済みです。
   memory_limit = 32M
3. httpdの再起動
   /etc/rc.d/init.d/httpd condrestart

IEの
[ツール]-[インターネット オプション]-[Cookieの削除]と[ファイルの
削除](すべてのオフライン コンテンツを削除するにチェックを入れる)
を行い、一度閉じてから、もう一度「リンクから開く」、「直接開く」
両方で試しました。
上記の方法では、解決に至ることができませんでした。
 

--
こやま
puyoumailaddress @ yahoo.co.jp


PHP-users メーリングリストの案内