Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What to do if the php file cannot be opened after download

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "php file download can not be opened after how to deal with", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "php file download can not open how to deal with" it!

The file opens and shows the problem of corruption after PHP downloads the picture.

Use php to write a picture download method, the test found that the size of the downloaded pictures are all right, but can not open the file.

The solution is as follows:

First open the file to download the code and add

Ob_clean (); flush ()

Download the picture code completely

If (isset ($_ GET ["action"]) & & $_ GET ["action"] = "download") {if ($_ GET ["file"]) {$fileinfo = pathinfo ($_ GET ["file"]); header ("Content-type: application/x-". $fileinfo ["extension"]); header ("Content-Disposition: attachment; filename=favicon.ico"); ob_clean (); flush (); readfile ($_ GET ["file"]); exit ();}}

Content extension:

Php downloads the excel file

1. Do not output any non-file information, such as echo log information, during the download process. Otherwise, the downloaded file cannot be opened, indicating that the format is incorrect or the file is corrupted.

2. The output excel format must be kept with the suffix name, otherwise it will also prompt the format error or the file is corrupted.

The code is as follows:

If (file_exists (CACHE_PATH. $file_name) {/ / $this- > logger- > error ("file realpath:" .realpath (CACHE_PATH. $file_name); header ("Pragma: public"); header ("Expires: 0"); header ("Content-Encoding: none"); header ("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header ("Cache-Control: public"); header ("Content-Type: application/vnd.ms-excel"); header ("Content-Description: File Transfer") Header ("Content-Disposition: attachment; filename=". $file_name); header ("Content-Transfer-Encoding: binary"); header ("Content-Length:". Filesize (CACHE_PATH. $file_name); readfile (CACHE_PATH. $file_name);} else {$this- > logger- > error ("export model:". $id. " Error: no production file "); echo";} Thank you for your reading, the above is the content of "php file can not be opened after download". After the study of this article, I believe you can not open the php file after downloading how to deal with this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report