PHP file downloading: the solution to corrupted PHP file content with garbled characters requires PHP file downloading.
Just copy the code and change it.
A lot of results have also come out.
After clicking download, I thought the file was downloaded. who knows that the file was damaged when the image was opened, so I observed the file size. it seems that it is about 1 KB more.
Use PS to open it. well, the system prompts that the image is damaged, but the image can be displayed.
So I think it's the extra 1kb problem.
Then, I upload a txt file and download it.
It was found that the front and back of the file contain a few more characters.
Then I was wondering how to remove it. various Baidu, Google, and questions on the forum.
Finally, after more than an hour of searching, 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); }}
Note:
ob_clean();flush();
This is the key. with these two functions, the image is opened normally and the text is not garbled.
Reprinted from: http://www.9958.pw/post/download_content