file permissions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

file permissions

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

doesn't work.. how?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

thats what im askin! any sugestions to auto chmod a folder?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no. I mean how is it not working. The directory didn't get created. Or the chmod is different than "expected"
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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!
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

safemode is on...how would u do the ftp thing?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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"??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you aren't sending a site command.. just a path.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply