Jump to content

Archived

This topic is now archived and is closed to further replies.

spelltwister

Write to server

Recommended Posts

Hi all,

I have a script that writes files to my server:

[code]
$data = "<?xml version=\"1.0\"?>\n"; 
$data .= "<units>\n";
...
$data .="</units>";
$file = "/path.xml";   
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; } 
if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; } 
fclose($file_handle);[/code]

the problem is that it only writes the files when the server runs a cron job.  Otherwise, it can't run them.  I know the problem is folder permissions, however I'm not sure how to set them to get this result:

1.  I do not want to make the folder writable from everywhere
2.  I want to be able to accept an xml file upload and write to the server

Is there a way to "login" as the server or add something to my script that will allow it to write to the server and no one else?

Thanks,

Mike

Share this post


Link to post
Share on other sites
I think if you do a chmod to 744 on the directory it will enable read/write/execute for the owner, and read only for all others.

Share this post


Link to post
Share on other sites
owner is already r/w/e.  Here's two example of what I want:  I go to a page, fill out a form, hit submit and i want to generate xml files. (if this has to be full write access on the folder, I'll figure something else out).
Secondly:  I upload an xml file to a page, it parses it, runs calcs, etc, and then writes another one.  Is this able to be done with just owner r/w/e?

Thanks

Share this post


Link to post
Share on other sites
In order to write a file to a directory, the directory has to have write access enabled for the user that is writing to it.  Generally, if the web server is writing, then you can get away with either 744 or 764, depending on how the groups are set up, if at all.

Try setting up the permissions as 764 or 777 and reducing them until you are no longer able to achieve what you want, then decide if that is too high for your comfort.

Share this post


Link to post
Share on other sites
can you please say what groups are?
Also, is there a way that in the script i can make it as thought the webserver is doing the writing.  I know that the only way to wirte right now is 777

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.