Home >Backend Development >PHP Problem >What should I do if the php file cannot be opened after being downloaded?
The solution to the problem that the php file cannot be opened after downloading: first open the file to download the code; then add the "ob_clean();flush();" statement to the file.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if the php file cannot be opened after downloading? ?
Solution to the problem of file opening showing damage after downloading pictures with PHP
Use PHP to write a picture downloading method. The test found that the size of the downloaded pictures is fine, but the file cannot be opened.
The solution is as follows:
Add these 2 sentences
ob_clean(); flush();
.
Complete download image code:
PHP
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(); } }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if the php file cannot be opened after being downloaded?. For more information, please follow other related articles on the PHP Chinese website!