mkdir problems setting chmod

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

Post Reply
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

mkdir problems setting chmod

Post by andylyon87 »

havin a problem with the mkdir property

have successfully made the directory using

Code: Select all

mkdir($target, 0777);
However this is presenting a problem, this is created then the thing cant be deleted from the server over FTP. I look at the permissions on the server and they read 0755. Am I doin something wrong or what.

Thanks
Andy
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

If you call mkdir() in PHP, that directory is being given the ownership of the apache user. If the permissions are set to 0755, then only the owner of that directory (which would be apache), can delete that folder. You need to either
  • give full rights to the group of that directory and make sure you're account is in that group,
  • give full rights to the world, or
  • change the ownership (chown is the linux command, not sure if there's a PHP equivalent) of the folder to you're account, after making the directory.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I've run into this problem before in a shared environment. I was told by the host that chown() is not available.

FYI
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

It differs from host to host of course, but if they *have* disabled chown, check if they've disabled shell_exec() (they probably have) and you can call the linux chown yourself.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

if chown() isn't enabled is there anyway in the chmod to change it.

How would I make it accessible to the world?
How would I make it deletable?

Thanks
Andy
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Instead of using mkdir you could use the ftp extension to login into localhost, and create it from there... This way the directory is owned by the ftp-user ;)
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

how would I go about that cos that makes more sense to me.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

check out ftp_connect() and go from there. i had the exact same problem as you a while back and thats how i fixed it
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

how would I go about creatin a new folder using that command
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

would I use ftp_connect() and then ftp_mkdir()
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

Code: Select all

<?php
$ftp_server = "ftp://myftp";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

$dir = 'www/users/andy';

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to create the directory $dir
if (ftp_mkdir($conn_id, $dir)) {
 echo "successfully created $dir\n";
} else {
 echo "There was a problem while creating $dir\n";
}

// close the connection
ftp_close($conn_id);
?>
What am I doin wrong, the ftp is right cos I accessed it, but it keeps throwin up stuff.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);

$host = "myftp";
$user = "andy";
$pass = "password";

$dir = "/www/users/andy";

echo "<br/>connecting $host: ";
$ftp = ftp_connect($host);
if ($ftp === false)
{
  echo "failed";
}

echo "<br/>logging in $user / $pass: ";
if (!ftp_login($ftp, $user, $pass))
{
  echo "failed";
}

echo "<br/>creating $dir: ";
if (ftp_mkdir($ftp, $dir) === false)
{
  echo "failed";
}
else
{
  echo "succes";
}

ftp_close($ftp);
?>
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

thanks mate that works perfect, and I understand a lot more what you guys meant


andy
Post Reply