send zip file to browser / force direct download

后端 未结 4 1323
感情败类
感情败类 2020-12-06 00:47

i created with php zip ( http://php.net/manual/de/book.zip.php ) a zip file

now i have to send it to the browser / force a download for it.

4条回答
  •  Happy的楠姐
    2020-12-06 01:28

    Set the content-type, content-length and content-disposition headers, then output the file.

    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename="'.$filename.'"');
    header('Content-Length: '.filesize($filepath) );
    readfile($filepath);
    

    Setting Content-Disposition: attachment will suggest the browser to download the file instead of displaying it directly.

提交回复
热议问题