Forum Moderators: coopster

Message Too Old, No Replies

Creating directories with PHP

         

Psychopsia

8:19 pm on Feb 17, 2007 (gmt 0)

10+ Year Member



Hey hi!

I have a problem since a long time with a script that creates directories, when executes the following code create it with the owner and group as 'nobody' but don't allow me to work inside the folder.


if (!@file_exists($thumbs_path) ¦¦!@is_dir($thumbs_path))
{
$old_umask = umask(0);
@mkdir($thumbs_path, 0777);
umask($old_umask);
//@chmod($thumbs_path, 0777);
}

Should I uncomment and move the chmod line before umask?

Is there a way to set the owner to my user when creates it, not to 'nobody' without using chown and chgrp?

Thank you!

mcavic

12:09 am on Feb 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On most systems, you can't change the owner of an existing file or folder unless you're root, so chmod 777 after mkdir would be the best easy way.

There are workarounds using setuid or ftp, but on a shared server, those tend to be less secure.

Psychopsia

3:14 pm on Feb 19, 2007 (gmt 0)

10+ Year Member



I was thinking in another solution:

Setup an FTP user to access to a specific path and after use the PHP script to login by FTP and create a folder and give 0777 permissions. So, this folder will have my user as owner or 'nobody'?

I don't want to try again this method before know what might be happen because I must contact my host to set the folder to my user to be able to work inside it.

Psychopsia

6:17 pm on Feb 20, 2007 (gmt 0)

10+ Year Member



I written a light version of the FTP via PHP, without OOP:

<?php

$conn = ftp_connect($host);
ftp_login($conn, $ftp_user, $ftp_pass);

@ftp_chdir($conn, './data/');
@ftp_mkdir($conn, 'test1');
@ftp_chmod($conn, 0777, 'test1');
ftp_close($conn);

?>

Who will be the owner/group of the directory? FTP_user, main user account or 'nobody'?

Psychopsia

2:26 pm on Feb 21, 2007 (gmt 0)

10+ Year Member



Somebody knows? :(

jatar_k

2:56 pm on Feb 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



not sure, try creating a dir and then see who owns it, you would think it would be the ftp user since you logged in with that user and that's how you created the dir