Exemplo n.º 1
0
  function mkdir($dir, $perm=0777, $parents=true)
  {
    if(is_dir($dir))
      return;

    $dir = Fs :: normalizePath($dir);

    if(!$parents)
    {
      Fs :: _doMkdir($dir, $perm);
      return;
    }

    $separator = Fs :: separator();

    $path_elements = Fs :: explodePath($dir);

    if(count($path_elements) == 0)
      return;

    $index = Fs :: _getFirstExistingPathIndex($path_elements, $separator);

    if($index === false)
    {
      return throw_error(new IOException('cant find first existent path', array('dir' => $dir)));
    }

    $offset_path = '';
    for($i=0; $i < $index; $i++)
    {
      $offset_path .= $path_elements[$i] . $separator;
    }

    for($i=$index; $i < count($path_elements); $i++)
    {
      $offset_path .= $path_elements[$i] . $separator;
      Fs :: _doMkdir($offset_path, $perm);
    }
  }