首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从HTML页面通过PHP打开文件

问无法从HTML页面通过PHP打开文件
EN

Stack Overflow用户
提问于 2014-03-25 08:27:29
回答 2查看 129关注 0票数 0

使用file.asp提供的示例,我正在使用html学习php。在尝试通过在浏览器上点击html文件在服务器上使用php打开文件时,我发现没有在服务器上创建任何文件,而php部件似乎没有在那里运行。下面是我使用的确切文件

代码语言:javascript
复制
<html>
<body>

<?php
$file=fopen("welcome.txt","w+");
fwrite($file, "test");
?>

</body>
</html>

Below are apache details,
[root@ learneg]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Feb  7 2012 09:50:11

我也尝试过其他的密码,但没有成功。请给我建议一下我在这里可能会错过什么

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-25 08:30:56

您需要配置Apache,因此它也将解析.html文件。查找AddType在httpd.conf中的部分并添加/取消注释如下:

AddType应用程序/x .htm

AddType应用程序/x .html

票数 1
EN

Stack Overflow用户

发布于 2014-03-25 08:31:34

对此应该有一个简单的解释。

你在apache上运行它。

代码语言:javascript
复制
1) Is php5 installed on apache ?

2) Are you sure the php5 module is enabled ?

3) Does the file have a .php extension ?

Apache只在看到.php扩展时才解析php。

您也可以尝试这样做:

代码语言:javascript
复制
$file_contents = fopen( "<yourfile>", "r" );
print $file_contents; // This prints the output if it can find it.
fclose($file_contents);
// Write it to a another file.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22628968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档