gpt4 book ai didi

php - 使用 php 创建一个空的 html 文件

转载 作者:太空宇宙 更新时间:2023-11-04 13:36:50 24 4
gpt4 key购买 nike

我正在尝试通过 php 创建一个空白的 html 文件。我写了一些代码,但它似乎不起作用。这是我的代码:

            $filename = 'test.html';        
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");

当我单击将创建此文件的链接时,它会给我一个 html 文件,但当我看到源代码时,它会显示我请求此文件的页面的源代码。

为什么这行不通有什么原因吗?另外,什么是更快?每次用户询问时生成一个 html 文件,或者只提取一个创建的空文件并在用户询问时重命名它?谢谢!

最佳答案

您可能想使用 fopen 函数:

$file = fopen("test.html", 'w') or die("can't open file");
fclose($file);

这应该在与执行代码的 .php 文件相同的路径中创建一个名为 test.html 的文件

关于php - 使用 php 创建一个空的 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10527321/

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