首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过php下载的文件是否损坏/大小增加?

问通过php下载的文件是否损坏/大小增加?
EN

Stack Overflow用户
提问于 2011-11-16 05:15:23
回答 1查看 186关注 0票数 0

我有这样的代码:

代码语言:javascript
复制
    $file = $tempDir . "/download.zip";
    // there's some omitted code here that creates the file that's to be downloaded

    if(file_exists($file) && is_readable($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/zip');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
    }else{
        return "Error: Failed to retrieve file.";
    }

生成文件的代码运行良好,点击下载按钮后,我看到它出现在适当的位置,大小为1KB。该文件也是可用的。当我下载的时候,它甚至说它是"973字节“。然而,当文件真正下载时,它突然变成了9.1KB,并且完全损坏了。为什么?

EN

回答 1

Stack Overflow用户

发布于 2011-11-16 05:55:51

被省略的代码是否运行后台程序?如果您运行命令行程序(exec等)来创建zip文件,那么您提供的可能是一个不完整的文件。

上传一个你知道可以工作的zip文件,删除创建zip的代码,看看它是否被正确提供。如果不是,请告诉我,我会看一看。这是windows还是linux?

此外,文件的大小可能会略有不同。windows添加元数据、创建、添加、修改等会影响文件大小

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8143234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档