readfile返回损坏的zip下载

时间:2018-06-08 14:29:41

标签: php phalcon

我的Phalcon应用程序中有以下代码。

public function downloadAction($key = NULL) {
    if ($key == NULL) {
        return $this->respondDownloadFailed();
    }

    $url = Urls::findFirst("token = '".$key."'");

    if ($url) {
        $path = $url->getUrl();

        $ext = pathinfo($path, PATHINFO_EXTENSION);

        header("Content-type: application/".$ext); 
        header("Content-Disposition: attachment; filename=".$key.".".$ext);
        header("Content-length: " . filesize($path));
        header("Pragma: no-cache"); 
        header("Expires: 0"); 

        ob_clean();
        flush();

        readfile($path);
        unlink($path);
        die;
    }

    return $this->respondDownloadFailed();
}

现在,当在服务器上创建.zip时,我可以打开并解压缩它。但是,当我通过上面的代码下载它时,我得到一个zip文件然后解压缩到.cpgz文件。当取消归档那个时,我再次获得.zip。关于出了什么问题的任何想法?

0 个答案:

没有答案