Page 1 of 2

file permissions

Posted: Wed Jan 05, 2005 9:26 pm
by shiznatix
i want to create a directory and then autmatically chmod to 0777. iv tried this

Code: Select all

<?php
$makedir = mkdir("users/$username", 0777);
?>
but that dont work? why?

Posted: Wed Jan 05, 2005 9:31 pm
by feyd
doesn't work.. how?

Posted: Wed Jan 05, 2005 9:40 pm
by shiznatix
thats what im askin! any sugestions to auto chmod a folder?

Posted: Wed Jan 05, 2005 9:54 pm
by feyd
no. I mean how is it not working. The directory didn't get created. Or the chmod is different than "expected"

Posted: Wed Jan 05, 2005 10:23 pm
by shiznatix
diffrent that expected the folders created but the chmod is so only the "owner" can write but i want everyone to be able to write!

Posted: Wed Jan 05, 2005 10:31 pm
by rehfeld
if safemode is NOT on, try this

Code: Select all

$old = umask(0);
chmod("/some/dir", 0755);
umask($old);
if safemode is on, you cant do anything about it. its a limitation of safemode.
you could however use php's ftp functions to log in via ftp on the fly, and create the directory that way.

Posted: Wed Jan 05, 2005 10:34 pm
by shiznatix
safemode is on...how would u do the ftp thing?

Posted: Wed Jan 05, 2005 10:36 pm
by rehfeld
http://www.php.net/ftp

i beleive someone actually posted a code sample of how to do it via ftp on the page for mkdir() though

Posted: Wed Jan 05, 2005 11:30 pm
by shiznatix
ok im trying to do it through the ftp but i keep getting

Warning: ftp_site(): example/example/: Operation not permitted

my code is

Code: Select all

<?php
$ftp_server = "ftp.example.com";
$ftp_user = "username";
$ftp_pass = "password";
$ftp_file = "path/to/dir/i/want/to/chmod0777";

$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 
// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
   ftp_site($conn_id, $ftp_file);
} else {
   echo "Couldn't connect as $ftp_user";
}
// close the connection
ftp_close($conn_id);
?>
why is this "not permitted"??

Posted: Wed Jan 05, 2005 11:47 pm
by feyd
you aren't sending a site command.. just a path.

Posted: Thu Jan 06, 2005 12:02 am
by shiznatix
sorry while deleting my personal info i deleted under $ftp_file somtin important that i do have in my code. $ftp_file actually looks like this

Code: Select all

<?php
$ftp_file = "chmod 0777 example/example/example";
?>
so i am actually sending the command. my bad. also this is the 1st time iv ever used ftp commands in php so i really dont know all what im doing. i tried ftp_chmod also with a slightly diffrent code but it gave me a error saying that ftp_chmod isnt even a command at all...why?

Posted: Thu Jan 06, 2005 12:10 am
by feyd
ftp_chmod is php5 only.

As for the failure.. it may require an absolute path to the directory (that path does exist right?)

Posted: Thu Jan 06, 2005 12:14 am
by shiznatix
ya the path does exist (that one took me like 15 minutes to figure out :) )
as for the absolute path ill try that and post back

Posted: Thu Jan 06, 2005 12:20 am
by shiznatix
ok i tried

Code: Select all

<?php
ftp_site($conn_id, "CHMOD 0777 /folder/folder");
?>
but still same problem, but i dont think thats what u ment by direct path. elaborate on that because i dont get it :oops:

Posted: Thu Jan 06, 2005 12:40 am
by feyd
that's an absolute path, however, I'm not sure that's an actual location on the server. Typical is something like /home/some_username/public_html/folder/folder

It's also possible that when your script logs into ftp, it's in a different folder than you may think. Try using [php_man]ftp_pwd()[/php_man] to see where you are starting in.