So what I'm doing is creating a directory with a name from the file , then creating a text file in it.
My directory structure is like this where I am trying to create the file:
/users/username/www/practise
and the code is:
$path = /home/username/www/practise/
$counter_file = "/home/username/www/practise/counter.txt";
if (file_exists($counter_file)) {
line 2 : if(!($fp = fopen($counter_file, "r")))
die("can't open the file");
$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);
}
The error which I am getting is:
Warning: fopen(counter.txt): failed to open stream: Permission denied on line 2
can't open the file