Forum Moderators: coopster

Message Too Old, No Replies

Help with mkdir

and copying a file to the created directory

         

mtgmaster

2:49 am on Jan 22, 2006 (gmt 0)

10+ Year Member



Ive got a script where people can sign up and a folder is created with their username as the name of it. I also want to copy files to that directory using the same script but everything Ive tried doesnt work. Ive tried using the copy function and also fopen to make a new file but none of them have worked.

Code:


if(!is_dir($dirname)) {
$old_umask = umask(0);
mkdir("$dirname", 0777);
umask($old_umask);

$file = '/files/index.php';
$newfile = '/$dirname/index.php';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}

} else {
echo "URL taken";
die();
}

Thanks.

simon2263

11:14 am on Jan 22, 2006 (gmt 0)

10+ Year Member



What exactly isn't working? The mkdir or the copy? Is the mkdir succeeding? Do you see the error message when you execute the copy command? What are the permissions on the directory where you try to make the directory?

Simon

mtgmaster

9:27 pm on Jan 22, 2006 (gmt 0)

10+ Year Member



The directory gets created but the copy doesnt work. The CHMOD permissions of the created directories are 755 and there are no error messages.

Thanks.

simon2263

7:42 am on Jan 23, 2006 (gmt 0)

10+ Year Member



The permissions 755 mean rwxr-xr-x in unix speak, or, for the human user: the director owner gets to read/write/execute things, group members get to read and execute things, and others get to read and execute things .

The PHP script is being executed by the web server, which typically runs under the "nobody" user account (a security tactic since this account has minimal privileges). It might be that the relevant set of permissions for the dirctory that apply to the web server is the last three (for others) - i.e., read and execute. If you do a listing on the directory containing the created directories, can you see which user account owns the created directories? What happens if you set the permissions to 777 (meaning everyone can write to them)?

mtgmaster

11:22 am on Jan 23, 2006 (gmt 0)

10+ Year Member



I dont know how to view thw owner in a directory listing but when I try and change the permissions of the folder in an FTP client, they wont change, it stays at 755.

I read that 'nobody' is made owner on shared unix hosting so you have to use FtpMkdir, Ill try that.

Thanks.