getting fopen to work takes...?

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

getting fopen to work takes...?

Post 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?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

When you say 'a motd' file, do you mean THE motd file, i.e /etc/motd ?
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

If you 'chmod 666 /etc/motd' then you should be able to write to it.
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post 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.
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post 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 ;)
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

I GOT IT :lol:

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

edit: Thank you ;)
Post Reply