2014-03-01 36 views
0

所以我在做的是用文件中的名字创建一个目录,然后在其中创建一个文本文件。无法创建文件usind PHP?

我的目录结构是这样的,我想创建该文件:

/用户/名/ WWW /实践

而且代码:

$ path =/home/username/www/practice/

$ counter_file =“/home/username/www/practise/counter.txt”;

如果(file_exists($ counter_file)){

线2:(!($ FP =的fopen($ counter_file, “R”)))如果

模具(“不能打开文件“);

  $counter = (int) fread($fp, 20); 
      fclose($fp); 

      $counter = $counter + 1 ; 
     $path .= $counter 

      mkdir($path , 0777); 
      $path .= content.txt; 

      if (!($fp = fopen($path, "w"))) 
      { 
       die("cannot open the file"); 

      } 
      fwrite($fp, "{$content}"); 
    // content is the variable that has value equal to "file is created" 
      fclose($fp); 

      if(!($fp = fopen($counter_file, "w"))) 
       die("cann't open the file"); 

      fwrite($fp, $counter); 
      fclose($fp);   // and store the counter value in the file 

      if(!($fp = fopen("$counter_file", "w"))) 
       die("cann't open the file"); 

      fwrite($fp, $counter); 
      fclose($fp);    

}

我正的错误是:

警告:FOPEN(counter.txt):未能打开流:权限被拒绝上线2

无法打开文件

+0

尝试'/ practice/counter.txt'。 – putvande

+0

仍然是一样的错误@putvande – Deepu

+0

你有写权限吗? –

回答

1

也许您对目录有权限,但对您的文件没有权限。在您的txt文件上使用chmod(777)。 请记住,它不是最好设置777.

+0

如果不是读取文件,而是在写入模式下打开 – Deepu

+0

我不明白您的请求。而不是777只读文件? – Debflav

+0

有没有办法以777权限在写模式下打开文件? – Deepu