You are here

public function ActionQuickUpload::run in N1ED - Visual editor as CKEditor plugin with Bootstrap support 8.2

Runs action.

Overrides AAction::run

File

src/Flmngr/FileUploaderServer/lib/action/ActionQuickUpload.php, line 24

Class

ActionQuickUpload

Namespace

Drupal\n1ed\Flmngr\FileUploaderServer\lib\action

Code

public function run($req) {
  $fileSystem = new FMDiskFileSystem([
    'dirFiles' => $this->config
      ->getBaseDir(),
    'dirCache' => '',
  ]);
  if ($req->file) {
    if (array_key_exists('dir', $_POST) && $_POST['dir'] && $_POST['dir'] != '/' && $_POST['dir'] != '' && $_POST['dir'] != '.') {
      $target_dir = basename($_POST['dir']);
      $path = dirname($_POST['dir']) == '.' || dirname($_POST['dir']) == '/' ? '' : '/' . dirname($_POST['dir']);
      $fullPath = basename($this->m_config
        ->getBaseDir()) . $path;
      $fileSystem
        ->createDir($fullPath, $target_dir);
      $uploadDir = $fileSystem
        ->getAbsolutePath($fullPath) . '/' . $target_dir;
      $req->m_relativePath = $_POST['dir'];
    }
    else {
      $target_dir = '';
      $fullPath = basename($this->config
        ->getBaseDir());
      $uploadDir = $fileSystem
        ->getAbsolutePath($fullPath) . '/' . $target_dir . '/';
      $req->relativePath = '/';
    }
    $file = new FileUploadedQuick($this->config, $uploadDir, $req->fileName, $req->fileName, $req->relativePath);
    $file
      ->upload($req->file);
    $resp = new RespUploadAddFile();
    $resp->file = $file
      ->getData();
    return $resp;
  }
  else {
    throw new MessageException(Message::createMessage(Message::FILES_NOT_SET));
  }
}