Search code examples
phpdrupaldrupal-7

How to create a folder in site->default->files with write read permissions with Drupal?


I'm working on Ubuntu and I need to create a folder in Drupal's default->files folder with write permission so that I would be able to add files to that folder later on.

Here is the code I have:

drupal_mkdir('public://' . $new_dir . '/');
$file = file_copy($file, 'public://' . $new_dir . '/' . $file_name);

Solution

  •     drupal_mkdir('public://' . $new_dir , 0777);
    

    if you need it to be recursive set third argument to true.

    update:

        $oldumask = umask(0);
        drupal_mkdir("public://". $new_dir , 0777);
        umask($oldumask);