php file download appears download file content garbled corrupt solution
In the PHP program, you need to use PHP to do the file download
Just do it. Copy the code and change it.
There's a lot of effects coming out.
Then click on the download, um, I thought the file download, who knows, the picture opened when the prompt file corruption, which I observed the size of the file. It seems to be a lot of about 1KB.
Use PS to open, well, prompted the damage, but the image can come out.
Then I think it's the more 1kb problem.
Then, I upload a txt and then download it.
Sure enough, there were a few more characters in front and behind the file.
Then I was wondering how to get rid of it. Various Baidu, Google, on the forum to ask questions.
Finally, after my one-hour search, I finally found a solution.
The code is as follows
public function download(){ $upload=M('upload'); $data=$upload->find($_GET['id']); if(empty($data)){ header('HTTP/1.0 404 Not Found'); header('Location: .'); }else{ $path='./public/Uploads/'.$data['savename']; header("Content-Type:".$data['type']); header('Content-Disposition: attachment; filename="'.$data['name'].'"'); header('Content-Length:'.$data['size']); ob_clean(); flush(); readfile($path); }}
Attention:
ob_clean();flush();
This is the key. With these two functions, done, the picture is open normally, the text is not garbled.
Reprinted from: Http://www.9958.pw/post/download_content