| 10:42 am on Oct 6, 2009 (gmt 0)|
why dont you change permissions, upload file and change permissions back to original?
else, you can try to ftp the file to the folder
| 12:22 pm on Oct 6, 2009 (gmt 0)|
if you chmod to 777 can the file then be created?
| 5:24 pm on Oct 6, 2009 (gmt 0)|
dougmcc1, this is usually because the php process runs as a different user than the account owner. You mention that the permissions on the relevant directory are 755; that means the only the owner can write to that directory (i.e. the owner's permissions are rwx--read, write, execute--while the permissions for other members of the group and for 'others' are each r-x--read and execute). This means that if the user that php process runs as is any user that is not the account owner or is not a member of the account owner's group, it cannot write to a file with 755 (or even 775) permissions.
To solve this problem, you can basically do one of two things (neither of which will be under your control without root access to the server):
- Run php as the account owner (the sever would need some form of suexec enabled to do this) in which case 755 permissions will be sufficient, or
- Change the group of the relevant directory to the group of the user the php process runs as in which case you'll need to set permissions to 775
Short answer: contact your host/sysadmin :)
| 5:52 pm on Oct 6, 2009 (gmt 0)|
Excellent info bedlam, thanks so much for that.
Unfortunately, I am the sys admin of my server :) But I do have root access to it, and I do have SuExec enabled.
How do I find out who the owner of the php script is, who the owner of the folder is, and how do I change the owners of the php script or owner or the folder if needed so that they match up?
| 6:04 pm on Oct 6, 2009 (gmt 0)|
Well, configuring suexec is probably outside my area of expertise, but for the simple project of making-the-directory-writable-by-php-scripts, you can do this:
- Run "chmod 777 directory-name" (where directory-name is the name of your directory)
- Write a file to that directory with php
- In a shell, run "ls -hal" to find out the group name of the resulting file
- Run "chgrp -R group-name directory-name" (where group name is the name you discovered just above)
- Run "chmod 775 directory-name" (you may need to do the same on directories inside this one to make them writeable)
| 11:26 pm on Oct 6, 2009 (gmt 0)|
Should I use putty to run the commands you suggested? And be logged in as the root user?
| 12:28 am on Oct 7, 2009 (gmt 0)|
Man this was much easier than it was made out to be.
All you have to do for php to be able to write to folders with 755 permissions is put 777 permissions on the folder above it (which allows the script to create folders within this folder), have the php script create the new folder itself that it will be storing files in, then change the folder permissions back to 755 for the folder above it.
Thanks bedlam for pointing me in the right direction!
| 5:42 am on Oct 7, 2009 (gmt 0)|
Yes you can do it. just change the mode to 777 when uploading and after uploading change it to 755 bak using php script. "CHMOD" use this for accomplish you taks.
use this function
| 7:28 am on Oct 7, 2009 (gmt 0)|
No need to keep changing the permissions back and forth between 777 and 755. Once the script creates the folder it can write to it with 755 permissions.