Why is my downloaded file is always damaged or corrupted?

后端 未结 5 949
故里飘歌
故里飘歌 2020-12-06 14:42

I have a very weird problem with my download script

it basically

1.gets a file id with "GET" method

2.gets the name and location

5条回答
  •  盖世英雄少女心
    2020-12-06 15:23

        if (file_exists($file)) {
    set_time_limit(0);
            header('Connection: Keep-Alive');
        header('Content-Description: File Transfer');
                header('Content-Type: application/octet-stream');
                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);
    
    
    }
    

提交回复
热议问题