gpt4 book ai didi

php - 文件显示在浏览器上而不是在 YII 网站中下载

转载 作者:行者123 更新时间:2023-11-30 01:20:04 26 4
gpt4 key购买 nike

文件显示在浏览器中而不是被下载。之前是可以用的。我对项目的其他部分做了一些更改。但是我没有触及这个功能,我不知道发生了什么。请帮助我。

         $filename=date("d-m-ys").".sql";
$handle = fopen($filepath."/".date("d-m-ys").".sql", 'w+');
fwrite($handle, $return);
fclose($handle);

$bits = @file_get_contents($filepath."/".date("d-m-ys").".sql");
header("Content-type: application/sql");
header('Content-Disposition: attachment; filename="'.$filename.'"');
print $bits;

最佳答案

我不完全确定什么会导致它停止运行,除非您更改了 PHP 版本,但请尝试以下操作:

像这样设置 Content-Length header :

header("Content-Length: ".filesize($filepath."/".date("d-m-ys").".sql"));

并且您可以使用 readfile 来避免此类内存问题,它会读取文件并将其直接输出到输出流。

  readfile($filepath."/".date("d-m-ys").".sql");

另一种可能性是,在设置这些 header 之前,您在应用程序的其他地方输出数据 - 这将导致问题,因为 header 只能在任何输出之前设置。

关于php - 文件显示在浏览器上而不是在 YII 网站中下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18649635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com