You are here

public function filedepot::createStorageFolder in filedepot 7

Same name and namespace in other branches
  1. 6 filedepot.class.php \filedepot::createStorageFolder()
1 call to filedepot::createStorageFolder()
filedepot::createFolder in ./filedepot.class.php
Call createFolderNode to create the folder which will trigger this method through filedepot_insert @global type $user

File

./filedepot.class.php, line 1006
filedepot.class.php Main class for the Filedepot module

Class

filedepot
@file filedepot.class.php Main class for the Filedepot module

Code

public function createStorageFolder($cid) {
  if (@is_dir($this->root_storage_path) === FALSE) {
    watchdog('filedepot', "Storage Directory does not exist (@path), attempting to create now", array(
      "@path" => $this->root_storage_path,
    ));
    $res = @mkdir($this->root_storage_path, FILEDEPOT_CHMOD_DIRS);
    if ($res === FALSE) {
      watchdog('filedepot', "Failed - check the folder path is correct and valid");
    }
    else {
      watchdog('filedepot', "Success, Root Storage director created");
    }
  }
  $path = $this->root_storage_path . $cid;

  //watchdog('filedepot', "Attempting to create path: @path", array("@path" => $path));
  if (file_exists($path) && @is_dir($path)) {
    @chmod($path, FILEDEPOT_CHMOD_DIRS);
    if ($fh = fopen($path . '/.htaccess', 'w')) {
      fwrite($fh, "deny from all\n");
      fclose($fh);
    }
    if ($fh = fopen("{$path}/submissions" . '/.htaccess', 'w')) {
      fwrite($fh, "deny from all\n");
      fclose($fh);
    }
    return TRUE;
  }
  else {
    $oldumask = umask(0);
    $res1 = @mkdir($path, FILEDEPOT_CHMOD_DIRS);
    $res2 = @mkdir("{$path}/submissions", FILEDEPOT_CHMOD_DIRS);
    umask($oldumask);
    if ($res1 === FALSE or $res2 === FALSE) {
      watchdog('filedepot', "Failed to create server directory @path or @path2", array(
        "@path" => $path,
        "@path2" => "{$path}/submissions",
      ));
      return FALSE;
    }
    else {
      if ($fh = fopen($path . '/.htaccess', 'w')) {
        fwrite($fh, "deny from all\n");
        fclose($fh);
      }
      if ($fh = fopen("{$path}/submissions" . '/.htaccess', 'w')) {
        fwrite($fh, "deny from all\n");
        fclose($fh);
      }
      return TRUE;
    }
  }
}