PHP -> Creating File

O

o[tter]

Guest
I made a page that is supposed to take some information, and create a new file in my directory. It is password protected, and its purpose is to allow me to easily add new pages to the site, without having to worry about my HTML. But, when I use the open command similar to this:

$filename = "bob.txt";
$fp = fopen($filename, "w");

...the file wont open. I tested $fp afterwards and it doesn't exist. What can I do to allow the script to make new files? Or do I have to make the files in advance?

Thanks.
 
S

ShockingAlberto

Guest
You are writing the file arn't you?
fwrite($fp,$data);
At a guess that is, since it's been a while since i looked at php. Make sure your private dir is chmod 777. That should effect the privacy, as that's done by apche, not the actual permissions.
 
O

o[tter]

Guest
Well, the files I want to write aren't in the private dir. They're in my main dir.
And... I tried writting, but since the file wont open, I just get an error.
 
T

Tempy_Incursion

Guest
Sometimes with PHP I find that the file needs to exist on the server, already CHMODed to 666 or 777. Try that and it should work. :(
 
T

Teaser

Guest
As far as I can remember, fopen() in PHP works similiar to that of fopen() in C in that if you do:

fopen ("blerugh.txt", "w")

it will create the file if it doesn't already exist, and if it does exist it will over-write the file. So, with right permissions, it should create the file without it already existing and without having to write to it (it'll just be empty).

Remember to fclose () it aswell.
 
T

Tempy_Incursion

Guest
Yes but if the file is to be created in the root folder you cannot set any permissions so like you say fopen() is meant create files even if they don't exist, but why isn't it working in this case? :confused:
 
M

MrChumble

Guest
Truth be told I'm not sure if this is relevent, but I'll throw it out in case and people can correct me if I'm speaking cobblers.

"Fopen does not handle redirects, this means that if you are running a
virtual domain, you will need the full path from the root (ie:
/home/users/me/web/file.txt), instead of the URL (ie: http://www.myvirtualdomain.com/file.txt)"

My apache knowledge is vague at best, so I'm not sure if yoursite.barrysworld.com would count as a virtual domain.
 
O

o[tter]

Guest
Well, fopen works on files that exist with 666 permission. The problem is that the php script is run as some account in another group. So it has to have write permission.

Is there any way to give it write permission to the whole folder without comprimissing my sites security?
 

Users who are viewing this thread

Top Bottom