Page 1 of 1

PHP - Writing to file (UNIX and Windows)

Posted: Mon Oct 06, 2003 11:31 am
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

Posted: Mon Oct 06, 2003 11:33 am
by AVATAr
you need (php neews) read permission, on that dir.

Posted: Mon Oct 06, 2003 12:45 pm
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).

Posted: Mon Oct 06, 2003 12:52 pm
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.

Win XP solution : failed to open stream: Permission denied

Posted: Tue Oct 07, 2003 11:42 pm
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