首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php文件读写

php文件读写
EN

Stack Overflow用户
提问于 2013-11-15 08:44:44
回答 1查看 101关注 0票数 0

所以我正在学习php,并试图为一个网页做一个php点击计数器。现在,我已经根据我的理解编写了这段代码。问题是,当我在终端中运行程序时,我得到了正确的答案(输出与我预期的一样)。当我在html页面上做回显时,它不工作。以下是代码

代码语言:javascript
复制
<html>
<body>
<?php
    #open the file (assuming this file already exists with only 0 in it)
    $file = 'test.txt';
    $file = fopen($file,"r");
    $temp = fread($file, 1024);
    fclose($file);

    #save the number 0 (initial counter to $temp) and delete it)
    $file = 'test.txt';
    unlink($file);

    #open the file (this line just creates the file to write)
    $file = fopen("test.txt","w");
    fclose($file);

    #increase the counter by a number (10 for testing)
    $temp = (int)$temp + 10;
    $file=fopen("test.txt","w");
    fwrite($file,"$temp \n")
    fclose($file);
    #the file only contains a number ($temp - the final counter)

    echo "<h1>$temp<h1>";  #this outputs the correct counter in terminal but only        outputs 10 on html page. ????? 

?>
</body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2013-11-15 10:08:11

我认为这是权限问题。尝试更改chmod/chown,例如:

代码语言:javascript
复制
sudo chown coders:www-data test.txt
sudo chown 765 test.txt
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19991423

复制
相关文章

相似问题

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