Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 20th, 2008, 12:29 PM
Registered User
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unable to write to files

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($fp20);
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!
 
Old December 23rd, 2008, 09:10 PM
Authorized User
 
Join Date: Dec 2008
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

make sure you have the file called count.dat in the same folder in which you have your php file.

thanks
 
Old December 27th, 2008, 07:26 PM
Registered User
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unable to Write file

I figured out a solution. I reinstalled PHP but now also installed Apache and MYSQL.
When I run PHP with Apache as my webserver instead of IIS, I am able to write files
 
Old December 29th, 2008, 02:27 PM
Authorized User
 
Join Date: Dec 2008
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

HI skprom

i am glad you have made it work, but i personally think that is not the solution to it.
I am not sure may be someone can correct me, i think PHP on windows runs faster with IIS, where as it runs faster on Linux with Apache..

Thanks & regards

Last edited by zeronexxx; December 29th, 2008 at 02:29 PM.. Reason: typo





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write files information to mysql db using p method PHP Databases 4 February 14th, 2006 09:18 PM
a problem about read and write the xml files watson C# 0 September 4th, 2004 10:33 AM
COM object to write files in asp flyin Classic ASP Components 1 September 29th, 2003 12:24 PM
Read(client) / write(server) files nazneen J2EE 1 July 2nd, 2003 05:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.