By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

N00b question: creating files

P: n/a
Hi,

I am rather new to PHP and a relative newbie to Linux too.
I have a webserver at home (Apache 2.0.48 on SuSe 9.0, PHP4).
I have some scripts, one of them needs to be able to create logfiles
somewhere on my machine. It must also later be able to read from and write
to these files again.

Sofar I get a permission error. I tried chmodding 666 or 777 the directory
in which the files could reside, to no avail.
How do I set up the permissions so that my script can simply fopen a file
for writing. Or if that's not the issue, what am I doing wrong or
overlooking ?

The errors:
Warning: fopen(logfiles\log1.txt): failed to open stream: Permission denied
in script1.php on line 142
Warning: fwrite(): supplied argument is not a valid stream resource in
script1.php on line 154
Warning: fclose(): supplied argument is not a valid stream resource in
script1.php on line 161
It's the first I am puzzled about, the 2nd and 3rd are a logical
consequence.

By the way, reading from and writing to a file I have previously created
myself with exactly the names I tried to get created by the script (echoed
the name, ok) is no problem at all.
So I don't think it has much to do with a safemode or open_basedir setting.
I also tried creating the scripts in the same dir the script itself resides.
Did not work either.

I think I listed all the relevant info here. Who can help me ?

TIA
Pjotr
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


On 4-Jul-2004, "Pjotr Wedersteers" <x3****@westerterp.com> wrote:
Warning: fopen(logfiles\log1.txt): failed to open stream: Permission
denied
in script1.php on line 142


try fopen('logfiles/log1.txt','w');

backslash is an escape. Assuming the your filename was in quotes it would be
interpreted as logfileslog1.txt, probably not what you want.

fopen also requires the mode as the second parameter. 'w' for write, 'a' for
append, etc

http://www.php.net/manual/en/function.fopen.php
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2

P: n/a

"Tom Thackrey" <us***********@nospam.com> wrote in message
news:YB*******************@newssvr29.news.prodigy. com...


On 4-Jul-2004, "Pjotr Wedersteers" <x3****@westerterp.com> wrote:
Warning: fopen(logfiles\log1.txt): failed to open stream: Permission
denied
in script1.php on line 142
try fopen('logfiles/log1.txt','w');

backslash is an escape. Assuming the your filename was in quotes it would

be interpreted as logfileslog1.txt, probably not what you want.

fopen also requires the mode as the second parameter. 'w' for write, 'a' for append, etc

http://www.php.net/manual/en/function.fopen.php


Your web server user needs write access to the folder you're trying to
create in, too. Check at the console. And post source that doesn't work so
we can see if there are obvious problems.

HTH
Garp
Jul 17 '05 #3

P: n/a

"Garp" <ga***@no7.blueyonder.co.uk> wrote in message
news:fN*********************@news-text.cableinet.net...

"Tom Thackrey" <us***********@nospam.com> wrote in message
news:YB*******************@newssvr29.news.prodigy. com...


On 4-Jul-2004, "Pjotr Wedersteers" <x3****@westerterp.com> wrote:
Warning: fopen(logfiles\log1.txt): failed to open stream: Permission
denied
in script1.php on line 142
try fopen('logfiles/log1.txt','w');

backslash is an escape. Assuming the your filename was in quotes it

would be
interpreted as logfileslog1.txt, probably not what you want.

fopen also requires the mode as the second parameter. 'w' for write, 'a'

for
append, etc

http://www.php.net/manual/en/function.fopen.php


Your web server user needs write access to the folder you're trying to
create in, too. Check at the console. And post source that doesn't work so
we can see if there are obvious problems.

What a silly mistake of me to use the wrong windoze backslashes. SIGH. But
it works now, thanks for the pointers. Rights have been properly assigned
now, webuser has rw rights to the directory.

Back to the development table to further exploit that fine PHP! I like it
sofar!
Pjotr
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.