Home >Backend Development >PHP Problem >What should I do if the php file cannot be opened after being downloaded?

What should I do if the php file cannot be opened after being downloaded?

藏色散人
藏色散人Original
2021-07-17 09:25:212500browse

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.

What should I do if the php file cannot be opened after being downloaded?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn