将zip文件发送到浏览器/强制直接下载 [英] send zip file to browser / force direct download

查看:537
本文介绍了将zip文件发送到浏览器/强制直接下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用php zip创建( http://php.net/manual/de/book.zip.php )一个zip文件

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.

推荐答案

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

这篇关于将zip文件发送到浏览器/强制直接下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆