Page 1 of 1

getting fopen to work takes...?

Posted: Wed Feb 18, 2004 1:53 pm
by redhair
Asking this makes me feel sooo new lol...

I'm trying to let php create a "motd" file.

To start doing so, I thougt I should make use of fopen(); with W+ option.
So, if the file don't exsist, it will be created.

But what happens...
permission denial.

Even chmod didnt work.

So I went looking on the web (hey I'm not that new...)

And it says at php.net:

If you are experiencing problems with reading and writing to files and you're using the server module version of PHP, remember to make sure that the files and directories you're using are accessible to the server process.

Unfortunaly, this doesnt tell what I should do when this error is there....well ok, it does, but very minor.

"make sure that the files and directories you're using are accessible to the server process"

This is to cryptic for me..

btw:
safe mode=off
allow_url_fopen=on
open_basedir=off

Also, I have full control of the server.

...what to do now?

I think I should give php the right to create files.

How?

Posted: Wed Feb 18, 2004 1:56 pm
by markl999
When you say 'a motd' file, do you mean THE motd file, i.e /etc/motd ?

Posted: Wed Feb 18, 2004 1:58 pm
by redhair
markl999 wrote:do you mean THE motd file, i.e /etc/motd ?
Yep...
I want php to create it (at least that is the planning),
then copy the file to /etc/, overwriting the original.

Posted: Wed Feb 18, 2004 2:06 pm
by markl999
If you 'chmod 666 /etc/motd' then you should be able to write to it.

Posted: Wed Feb 18, 2004 2:15 pm
by redhair
error bugger:

Warning: fopen(motd) [function.fopen]: failed to create stream: Permission denied in /var/www/html/motd/index.php on line 5

Warning: fputs(): supplied argument is not a valid stream resource in /var/www/html/motd/index.php on line 7

Warning: fclose(): supplied argument is not a valid stream resource in /var/www/html/motd/index.php on line 8

the code:

Code: Select all

<?php

$n = "Today's wisdom: php rockes!";

$f = fopen ("motd", "w+");

fputs($f, $n);
fclose($f);

?>
It works on my other machine...but not on my linux.

Posted: Wed Feb 18, 2004 2:16 pm
by redhair
markl999 wrote:If you 'chmod 666 /etc/motd' then you should be able to write to it.
Hold it right there....
Didnt get to the copy part yett!

Look at my code above ;)

Posted: Wed Feb 18, 2004 2:22 pm
by redhair
I GOT IT :lol:

turns out permissions of the folder /var/www/html/motd was set wrong..

edit: Thank you ;)