php user rights to write onto server during sessions
I need an advice for the following scenario:
I've build an admin section for a website which provides functions to update a website when new content is entered in a text file on the server. The admin section has a button, which calls a function so the text file gets parsed and a html file is written.
The issue is that the folder in which the html is written needs to be chmod 777, because the called script is available through an url.
What I want to avoid is to set every folder in which something gets written to 777, because the root folder also needs 777, but I don't have the rights to set chmod for the root folder.
My idea is to make a login which connects to the ftp account, so that the person who has entered the right login data is registered as the ftp user and so 开发者_如何转开发the 777 chmod could be turned into 755. Is this possible? How long does a session last when I use ftp_connect (when I redirect to another php srcipt which also needs user rights)? Is there a more common solution for this kind of problem?
You simply need to change the owner of the folder to match the user:group that the webserver is running as.
For instance, if you're running Apache HTTPD on ubuntu, apache will be running as the www-data user and group.
You can then run:
$ chown www-data:www-data /var/www/html/yourwebapp/folder_you_want_to_write_in
$ chmod 755 /var/www/html/yourwebapp/folder_you_want_to_write_in
精彩评论