【发布时间】:2020-01-18 23:30:28
【问题描述】:
$data = base64_encode('Hello World');
// echo '<pre>';
// print_r(strlen(base64_decode($data)));
// echo '</pre>';
// exit;
//strlen(base64_decode($data));
//filepath
ob_clean();
//header("Cache-Control: no-store, no-cache");
header("Content-type: text/plain");
header("Content-length: ".strlen(base64_decode($data))."");
header("Content-Disposition: attachment; filename=qwe.Lot");
exit(base64_decode($data));
我想在上面的代码中从 PHP 中的字符串创建一个文件,我将它作为我的控制器。它只打印字符串而不下载文件。
- 如何在 Code Igniter 中从字符串创建文本文件?
更新 这是浏览器调试中的输出
【问题讨论】:
-
尝试使用 echo 而不是退出? (不确定这是否可行)
-
还有
Content-Type和Content-Length标题的大小写。 -
我使用了
echo (base64_decode($data));相同的结果,只是将字符串放在浏览器中而不是下载@ErtySeidohl -
@DhavalPurohit 我不明白你的意思
-
标题中的
t和l应该大写@gurradio
标签: php ajax string file codeigniter