私はphp zip(http://php.net/manual/de/book.zip.php)でzipファイルを作成しました
今、私はそれをブラウザに送信する/強制的にダウンロードする必要があります。
私はphp zip(http://php.net/manual/de/book.zip.php)でzipファイルを作成しました
今、私はそれをブラウザに送信する/強制的にダウンロードする必要があります。
<?php
// or however you get the path
$yourfile = "/path/to/some_file.zip";
$file_name = basename($yourfile);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Length: " . filesize($yourfile));
readfile($yourfile);
exit;
?>
content-type、content-length、content-disposition ヘッダーを設定し、ファイルを出力します。
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Length: '.filesize($filepath) );
readfile($filepath);
設定Content-Disposition: attachment
により、ファイルを直接表示するのではなく、ファイルをダウンロードするようブラウザに提案されます。
この方法で行う必要があります。そうしないと、zipが破損します。
$size = filesize($yourfile);
header("Content-Length: \".$size.\"");
したがって、content-lengthヘッダーには実際の文字列が必要であり、filesizeは整数を返します。