I am unable to open files for writing. I am getting the following message:
HTML Code:
<b>Warning</b>: fopen(./count.dat) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>C:\Inetpub\wwwroot\BegPHP5\Ch07\hit_counter01.php</b> on line <b>13</b><br />
<br />
<b>Warning</b>: fwrite(): supplied argument is not a valid stream resource in <b>C:\Inetpub\wwwroot\BegPHP5\Ch07\hit_counter01.php</b> on line <b>14</b><br />
<br />
<b>Warning</b>: fclose(): supplied argument is not a valid stream resource in <b>C:\Inetpub\wwwroot\BegPHP5\Ch07\hit_counter01.php</b> on line <b>15</b><br />
The code that generated the error is as follows:
PHP Code:
<?php
$counter_file = "./count.dat";
if(!($fp = fopen($counter_file, "r"))){
die ("Cannot open $counter_file.");
}
$counter = (int) fread($fp, 20);
fclose($fp);
$counter++;
echo "You're visitor No. $counter.";
$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
?>
The above code was downloaded from the books webiste and should run perfectly. I am
sure that it is a permission's issues but I do not know how to resolve it. I am also sure that the last 3 messages relate to the last 3 lines of code. The last 2 messages are a result of the programs failure to open the file for writing..
Question: How do I configure PHP so that it can write files as well as read them? I am using Microsoft Internet Information Service (IIS) as my web server and my operationg system is Windows XP Professional.
Thanks!