相关疑难解决方法(0)

为什么我下载的文件总是损坏或损坏?

我的下载脚本有一个非常奇怪的问题

它基本上

1.使用"GET"方法设置文件ID

2.从数据库中获取该文件的名称和位置

3.使用headers和readfile将它发送到客户端

但奇怪的是,该文件总是出现损坏或损坏

就像它是一个zip或rar文件文件大小是正确的,它打开确定

但我不能打开它内部的压缩文件,那是我得到文件损坏的错误

这是奇怪的因为如果代码有问题我甚至不能打开zip文件(或至少我认为我不应该)

另一件事是我在发送标题之前用它的路径打印出文件,以确保一切正常

我把文件地址放在网址上并下载文件,文件没问题

所以在发送标题之前一切都很好

这是我的代码

        $file_id = isset($_GET['id']) && (int)$_GET['id'] != 0 ? (int)$_GET['id'] : exit;


        //////// finging file info
        $file = comon::get_all_by_condition('files' , 'id' , $file_id );
        if(!$file) exit;
        foreach($file as $file){
        $location = $file['location'];
        $filename = $file['file_name'];
        }
        /////////////


        $site = comon::get_site_domian();

        $ext = trim(end(explode('.' , $filename )));
        $abslout_path = 'http://'.$site.'/'.$location.'/'.$filename;
        $relative = $location.'/'.$filename;



    ////////////////// content type 
            switch($ext) {
            case 'txt':
                $cType = 'text/plain'; 
            break;              
            case 'pdf':
                $cType = 'application/pdf'; …
Run Code Online (Sandbox Code Playgroud)

php file download

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

download ×1

file ×1

php ×1