dongwei8440
2015-03-30 08:30
采纳率: 100%
浏览 134
已采纳

readfile下载损坏的文件

I am facing a problem when i am trying to download a certain file from my localhost. Everytime i download a file, either a .docx, a .pdf or a .png it is always corrupt. I have spend multiple hours on finding a solution but nothing seems to work.

This is the script im running :

$file_download="loonadministratie/{$loon_id}/{$file}";
        if (file_exists($file_download)) {
                header('Content-Description: File Transfer');
                header("Content-Type: application/octet-stream/loonadministratie/{$loon_id}/");
                header('Content-Disposition: attachment; filename='.basename($file_download));
                header('Expires: 0');
                header('Cache-Control: must-revalidate');
                header('Pragma: public');
                header('Content-Length: ' . filesize($file_download));
                readfile($file_download);
                exit;
            }

Thanks in forehand

图片转代码服务由CSDN问答提供 功能建议

当我尝试从本地主机下载某个文件时,我遇到了问题。 每次我下载一个文件,无论是.docx,.pdf还是.png,它总是腐败的。 我花了几个小时寻找解决方案,但似乎没有任何效果。</ p>

这是我正在运行的脚本:</ p>

  $ file_download =  “loonadministratie / {$ loon_id} / {$ file}”; 
 if(file_exists($ file_download)){
 header('Content-Description:File Transfer'); 
 header(“Content-Type:application /  octet-stream / loonadministratie / {$ loon_id} /“); 
 header('Content-Disposition:attachment; filename ='。basename($ file_download)); 
 header('Expires:0'); 
 header  ('Cache-Control:must-revalidate'); 
 header('Pragma:public'); 
 header('Content-Length:'。filesize($ file_download)); 
 readfile($ file_download); \  n exit; 
} 
 </ code> </ pre> 
 
 

感谢正手</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题