Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';不要用PHP创建HTML文件_Php_Html_Function_File Io - Fatal编程技术网

Can';不要用PHP创建HTML文件

Can';不要用PHP创建HTML文件,php,html,function,file-io,Php,Html,Function,File Io,我试图使用PHP创建一个.html文件,并用数组的内容填充它,但我无法创建html文件。以下是我的功能: function viewPag(){ session_start(); $handler=fopen("view.php", 'w+'); for ($i=0; $i < count($_SESSION["Text"]); $i++) { fwrite($handler,$_SESSION["Text"][$i]); }

我试图使用PHP创建一个.html文件,并用数组的内容填充它,但我无法创建html文件。以下是我的功能:

function viewPag(){
    session_start();

    $handler=fopen("view.php", 'w+');

    for ($i=0; $i < count($_SESSION["Text"]); $i++) { 
        fwrite($handler,$_SESSION["Text"][$i]);
    }

    fclose($handler);

    header("Location: view.php");
}
函数viewPag(){
会话_start();
$handler=fopen(“view.php”,“w+”);
对于($i=0;$i
您可能不在您认为的文件夹中。使用
echo getcwd()
打印当前文件夹,然后使用相对路径将文件存储在所需位置

也可能是您的
fopen
呼叫由于权限问题而失败。在
fopen
调用后添加
if
以测试
$handler
值:

if (!$handler) {
    echo "Could not open file for writing. Aborting";
    die();
}

您真正应该做的一件事是查看日志并搜索错误。如果不查看日志,您(和我们)就是瞎了眼,不知道什么地方出了问题(可能是这个函数之前出了问题……我们无法确定)。

您不能在
.html
文件中运行PHP。但是,您可以通过编辑
.htaccess
文件来完成

使用扩展名
.php
保存文件,并按如下所示编辑
.htaccess
文件

AddType application/x-httpd-php .html
如果只想在一个页面中使用它,可以使用以下代码

<Files yourpage.html>
AddType application/x-httpd-php .html
</Files>

AddType应用程序/x-httpd-php.html

如果文件未创建,我建议1。检查http服务器错误日志文件和2。您可以实现错误处理。很可能您有权限问题。您不能创建是什么意思?发生了什么?你是对的,阿卡莎,这是一个权限问题…@Doruko你有什么文件系统/操作系统?我现在正在使用Ubuntu服务器