如何使用PHP修复下载的文件

时间:2019-07-03 10:31:21

标签: php file-handling force-download

所以基本上我整理了一个脚本来从文件夹下载文件。 但是,当我尝试使用Microsoft照片打开JPG或PNG或绘图时,它表示不支持该类型的文件时,一切正常。你知道为什么会这样吗?

我在这里有一些代码

 if(isset($_POST['download']))
{
$filename = $_POST['item'];
$file_url = "uploads/$nameu/$filename";

if (file_exists($file_url)) {
   header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; 
     filename="'.basename($file_url).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file_url));
    flush(); 
    readfile($file_url);
    }
    }

我非常感谢您提供的任何帮助。

0 个答案:

没有答案
相关问题