PHP - Writing to file (UNIX and Windows)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kaasu
Forum Newbie
Posts: 2
Joined: Mon Oct 06, 2003 11:31 am

PHP - Writing to file (UNIX and Windows)

Post by kaasu »

Hello, I am a PHP newbie and I have created a script to write some text to a file. It has been giving me this error

Warning: fopen(./category.xml): failed to open stream: Permission denied in c:\inetpub\wwwroot\PHP_Fusebox\csc513\act_generateXML.php on line 16
Cannot open file

Here is the code example

$myfilename = "./category.xml";
if (!($fp=fopen("$myfilename","w"))) die("Cannot open file");
if(!(fwrite($fp,"Hello world"))) die("Error in writing");
fclose($fp);

Any help is appreciated
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

you need (php neews) read permission, on that dir.
kaasu
Forum Newbie
Posts: 2
Joined: Mon Oct 06, 2003 11:31 am

Post by kaasu »

Thanks for the reply. Can you please explain a bit further, what does (php neews) stand for. I am running it on windowsXP or unix server (production).
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

sorry.. PHP "needs" read permission for that dir.

on unix chmod the dir (i supose you wiont have any problem here)
on xp try goint to preferences, Security.. or something to chang the permissions.
imago
Forum Newbie
Posts: 3
Joined: Tue Jul 15, 2003 5:16 am
Location: Australia
Contact:

Win XP solution : failed to open stream: Permission denied

Post by imago »

hello,

I had a similar problem with writing to a file in Windows XP. I found the answer at Microsoft's knowledgebase. See following link:

http://support.microsoft.com/default.as ... -US;307874

The information in this article applies to:
Microsoft Windows XP Professional
Microsoft Windows XP 64-Bit Edition

How to Disable Simple File Sharing
1.Click Start, and then click My Computer.
2.On the Tools menu, click Folder Options, and then click the View tab.
3.In the Advanced Settings section, clear the Use simple file sharing (Recommended) check box.
4.Click OK.

cheers,
Sam
http://www.imagoscape.com
Post Reply