PHP readfile() adding extra bytes to downloaded file

前端 未结 6 1012
难免孤独
难免孤独 2020-12-06 21:49

I am trying to troubleshoot an issue I am having with downloading a \"zip\" file from a php script. It seems that when I download the file using the following code, the dow

6条回答
  •  借酒劲吻你
    2020-12-06 22:33

    I had same problem So I used this headers and I got my solution.

        $filename = ABSPATH.'/wp-content/summary/user_content/'.trim($file);
        header('Pragma: public');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Description: File Transfer');
        header('Content-Type: text/text');
        header('Content-Disposition: attachment; filename="'.$file.'"');
        header('Content-Transfer-Encoding: binary');
        header('Cache-Control: max-age=0');
        readfile($filename);
        exit;
    

提交回复
热议问题