I set up a hitcounter so that each time someone goes to my site, one of 7 different sidebars loads up. There is a file called counter.php that writes to a text file called hitcounter.txt. All the references to files seem to be relative but when I moved them to a new directory at my new host I got this error instead of a happy hit counter:

我设置了一个hitcounter,这样每次有人去我的网站时,7个不同侧边栏中的一个会加载。有一个名为counter.php的文件,它写入一个名为hitcounter.txt的文本文件。所有对文件的引用似乎都是相对的,但是当我将它们移动到我的新主机的新目录时,我得到了这个错误,而不是一个快乐的点击计数器:

Warning: fopen(hitcounter.txt) [function.fopen]: failed to open stream: Permission denied in /usr/local/apache/sites/MY-SITE/counter.php on line 5

警告:fopen(hitcounter.txt)[function.fopen]:无法打开流:第5行/usr/local/apache/sites/MY-SITE/counter.php中的权限被拒绝

Counter.php is pasted in its entirety below, line 5 is the first reference to fopen, both counter.php and hitcounter.txt have 775 permissions, same as they did on the old host.

Counter.php完全粘贴在下面,第5行是fopen的第一个引用,counter.php和hitcounter.txt都有775个权限,与旧主机上的权限相同。

What am I doing wrong? I'm obviously missing something really simple and embarrassing, so feel free to give me any scorn or abuse with while helping me out.

我究竟做错了什么?我显然错过了一些非常简单和令人尴尬的事情,所以在帮助我的时候随意给我任何蔑视或虐待。

counter.php:

<?php
    $count_my_page = ("hitcounter.txt");
    $hits = file($count_my_page);
    $hits[0]++;
    $fp = fopen($count_my_page , "w");
    if ($fp) {
        fputs($fp , "$hits[0]");
        fclose($fp);
    }
    if($hits[0]<=1)
        $random_number=0;
    else if($hits[0]>1 && $hits[0]<=2)
        $random_number=1;
    else if($hits[0]>2 && $hits[0]<=3)
        $random_number=2;
    else if($hits[0]>3 && $hits[0]<=4)
        $random_number=3;
    else if($hits[0]>4 && $hits[0]<=5)
        $random_number=4;
    else if($hits[0]>5 && $hits[0]<=6)
        $random_number=5;
    else if($hits[0]>6 && $hits[0]<=7)
        $random_number=6;
    else if($hits[0]>7 && $hits[0]<=8)
        $random_number=7;
    else if($hits[0]>8 && $hits[0]<=9) {
        $random_number=8;
        if($hits[0]==9) {
            $count_my_page=("hitcounter.txt");
            $fp = fopen($count_my_page , "w");
            $hits[0]=0;
            fputs($fp , "$hits[0]");
            fclose($fp);
        }
    }
?>

4 个解决方案

#1


First, you don't need 775 permissions. You need 666 permissions on the hitcounter.txt. The PHP file can be 644.

首先,您不需要775权限。您需要在hitcounter.txt上拥有666权限。 PHP文件可以是644。

The web server probably isn't a member of the group, depending on the host, so you'd need to give the 'Everyone' group write permissions.

Web服务器可能不是该组的成员,具体取决于主机,因此您需要为“Everyone”组授予写入权限。

The "Execute" bit is needed for folders but not for individual files, since they are not being executed by the OS.

文件夹需要“执行”位,但个别文件不需要,因为它们不是由OS执行的。

So you know, the 775 is : Owner, Group, Everyone

所以你知道,775是:所有者,团体,每个人

  • Owner = Read + Write + Execute

    所有者=读取+写入+执行

  • Group = Read + Write + Execute

    组=读+写+执行

  • Everyone = Read + Execute

    每个人=阅读+执行

666 means

  • Owner = Read + Write

    所有者=读取+写入

  • Group = Read + Write

    组=读+写

  • Everyone = Read + Write

    每个人=读+写

644 means

  • Owner = Read + Write

    所有者=读取+写入

  • Group = Read

    组=阅读

  • Everyone = Read

    每个人=阅读

更多相关文章

  1. mysql user表root 用户修改权限后出现无法访问数据库的解决方法
  2. 为mysql数据备份建立最小权限的用户
  3. 我需要提供哪些权限(如果有)我的Chrome扩展程序才能进行远程AJAX调
  4. res.partner上`write`的高级访问权限
  5. Linux的文件权限
  6. linux系统更改目录和文件的权限总结
  7. linux权限不够,sh不能用
  8. Linux学习笔记(九)--RedHat 7.0之用户身份与文件权限、存储结构与
  9. linux 可读可写可执行权限 chmod

随机推荐

  1. Go语言开发的Web框架都有哪些?
  2. PMP备考心得
  3. Android学习笔记3:使用日志工具
  4. 堆排序就这么简单
  5. 阻塞队列 BlockingQueue
  6. redis集群教程(二)
  7. 由浅入深,走进Python装饰器-----第五篇:
  8. SharePoint 解决方案:如何获取Library或者
  9. 希尔排序就这么简单
  10. Druid数据库连接池就是这么简单