php文件下载后不能打开怎么办
php文件下载后不能打开的解决办法:首先打开文件下载代码;然后在该文件中添加“ob_clean();flush();”语句即可。

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
php文件下载后不能打开怎么办?
PHP下载图片后文件打开显示损坏问题解决方法
用php写个图片下载方法,测试发现下载的图片大小都没问题,但是无法打开文件。
解决方法如下:
增加
ob_clean(); flush();
这2句话。
完整下载图片代码:
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();
}
}
推荐学习:《PHP视频教程》

