Page 1 of 1

mkdir problems setting chmod

Posted: Mon Jun 06, 2005 2:32 pm
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

Posted: Mon Jun 06, 2005 3:00 pm
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.

Posted: Mon Jun 06, 2005 3:22 pm
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

Posted: Mon Jun 06, 2005 5:52 pm
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.

Posted: Tue Jun 07, 2005 4:04 am
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

Posted: Tue Jun 07, 2005 5:17 am
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 ;)

Posted: Tue Jun 07, 2005 5:36 am
by andylyon87
how would I go about that cos that makes more sense to me.

Posted: Tue Jun 07, 2005 5:39 am
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

Posted: Tue Jun 07, 2005 5:49 am
by andylyon87
how would I go about creatin a new folder using that command

Posted: Tue Jun 07, 2005 5:50 am
by andylyon87
would I use ftp_connect() and then ftp_mkdir()

Posted: Tue Jun 07, 2005 6:33 am
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.

Posted: Tue Jun 07, 2005 7:18 am
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);
?>

Posted: Tue Jun 07, 2005 7:25 am
by andylyon87
thanks mate that works perfect, and I understand a lot more what you guys meant


andy