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?

藏色散人
Release: 2023-03-11 16:40:02
Original
2526 people have browsed it

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();
Copy after login

.

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();
}
}
Copy after login

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!

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template