Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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
使用php和my home server写入文件时出现问题_Php_Apache_Webserver_Debian_Lamp - Fatal编程技术网

使用php和my home server写入文件时出现问题

使用php和my home server写入文件时出现问题,php,apache,webserver,debian,lamp,Php,Apache,Webserver,Debian,Lamp,所以,我有一个简单的小php脚本。它运行和编译都很好,在我编写它的机器上按照我希望的方式工作。我正在运行Debian 6.0.6,32位的个人家庭网络服务器上运行它。它是apache和php。我知道php正在服务器上工作 <?php $hitsfile = "hits.txt"; #name of file $filehandle = fopen($hitsfile, '

所以,我有一个简单的小php脚本。它运行和编译都很好,在我编写它的机器上按照我希望的方式工作。我正在运行Debian 6.0.6,32位的个人家庭网络服务器上运行它。它是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.
    ?>

是否尝试检查该文件的权限?Linux文件系统有一个非常严格的权限系统。在终端上写入:

ls -la /path/to/my/file.txt

这将授予您在左列上的权限。请阅读以确保,并检查Apache是否具有该文件的“写入”权限。如果没有,请使用命令授予Apache对该文件的访问权限(如果该文件的所有者具有写入权限,则使用命令将该文件的所有者更改为Apache)。

确保该文件的权限允许写入该文件,并且该文件不是只读的。
var_dump(is_writable($hitsfile))告诉你?啊,耶,耶。哈哈。我爱你。:)如果这个答案对你有帮助,请勾选“V”标记我为正确答案。谢谢:)