所以,我有一个简单的小php脚本。它运行和编译得很好,并且在我编写它的机器上按照我想要的方式工作。我在一个运行Debian 6.0.6,32位的个人家庭web服务器上运行它。这是apache和php。我知道php是在服务器上工作的。
<?php
$hitsfile = "hits.txt"; #name of file
$filehandle = fopen($hitsfile, 'r') or die ("Couldn't read file."); #Opens file, 'hitsfile' to be read.
$hits = fread($filehandle, 5); #reads file to the introduced variable, 'hits'
fclose($filehandle); #closes file
$hits++; #increments the variable that it read.
$filehandle = fopen($hitsfile, 'w') or die ("Couldn't write to file."); #opens file to be read.
fwrite($filehandle, $hits); #writes the hits variable to file.
fclose($filehandle); #closes file.
echo $hits; #outputs the hits variable.
?>当我通过web浏览器从服务器访问文件时,我得到“无法写入文件”。错误。因此,它正确地打开了文件,并读取了它。当它打开它进行写入时,它会失败。我假设这是某种权限或其他方面的问题。我有点不知所措,不知如何解决这个问题。有什么想法吗?非常感谢您的帮助!我已经在谷歌上搜索了几天了,但我无法解决这个问题。我是一个php 'noob‘,我对运行基于linux的web服务器非常陌生,但是嘿,你一定要学会。:*l
发布于 2013-01-06 09:02:32
是否已尝试检查文件的权限?Linux文件系统具有非常严格权限系统。在终端上写入:
ls -la /path/to/my/file.txt这将为您提供对左列的权限。请阅读this article以确认,并检查Apache是否具有该文件的“写”权限。如果没有,请使用chmod命令授予Apache对该文件的访问权限(或者使用chown命令将该文件的所有者更改为apache,前提是该文件的所有者具有写入权限)。
https://stackoverflow.com/questions/14178173
复制相似问题