I am using this sample script I got from php.net but it doesn't seem to be setting the permissions correctly. If I then go in and run a chmod on them I can make the change but I need it to be 0777 when the directory is created. Any ideas?

What it is doing is first makes a folder named the job_id, then makes inside that folder a folder named the date.

so when my form gets processed it runs the function:
MakeDirectory($file_dir . $job_folder . $dir_date, 0777);

Thanks in advance.

function MakeDirectory($dir, $mode)
{
  if (is_dir($dir) || @mkdir($dir,$mode)) return TRUE;
  if (!MakeDirectory(dirname($dir),$mode)) return FALSE;
  return @mkdir($dir,$mode);
}

    I'm not sure but I think that when you mkdir, it inherits permissions based on its parent. Also, I think it has to do with the umask setting (which I've never fully understood). Sorry, I wish I had a better answer but this might point you in the right direction.

    Does this have to be recursive? Can't you just mkdir directory1, and then follow it with another command, mkdir directory1/directory2 ?

    Also, if the permissions aren't right when the directory was created, have you tried calling the chmod command in the PHP script after you create the directory?

      Write a Reply...