You are here

protected function elFinderVolumeDrupal::_save in elFinder file manager 8.2

Same name and namespace in other branches
  1. 6.2 inc/elfinder.drupalfs.driver.inc \elFinderVolumeDrupal::_save()
  2. 7.3 inc/elfinder.drupalfs.driver.inc \elFinderVolumeDrupal::_save()
  3. 7.2 inc/elfinder.drupalfs.driver.inc \elFinderVolumeDrupal::_save()

Create new file and write into it from file pointer. Return new file path or false on error.

@author Dmitry (dio) Levashov, Alexey Sukhotin

Parameters

resource $fp file pointer:

string $dir target dir path:

string $name file name:

Return value

bool|string

File

src/Controller/elFinderVolumeDrupal.php, line 228
elFinder driver for Drupal filesystem.

Class

elFinderVolumeDrupal
@file

Code

protected function _save($fp, $dir, $name, $stat) {
  $tmpname = $name;
  $bu_ret = \Drupal::moduleHandler()
    ->invokeAll('elfinder_beforeupload', array(
    'name' => $name,
    'dir' => $dir,
    'stat' => $stat,
  ));
  if (isset($bu_ret)) {
    if (!is_array($bu_ret)) {
      $bu_ret = array(
        $bu_ret,
      );
    }
    $tmpname = end($bu_ret);
  }
  $path = $dir . DIRECTORY_SEPARATOR . (!empty($tmpname) ? $tmpname : $name);
  if (!$this
    ->CheckUserQuota()) {
    return FALSE;
  }
  if (!$this
    ->CheckFolderCount($dir)) {
    return FALSE;
  }
  if (!$this
    ->CheckExtension($this
    ->_drupalfileobject($path))) {
    return FALSE;
  }
  if (!($target = @fopen($path, 'wb'))) {
    return FALSE;
  }
  while (!feof($fp)) {
    fwrite($target, fread($fp, 8192));
  }
  fclose($target);
  @chmod($path, $this->options['fileMode']);
  $file = $this
    ->_drupalfileobject($path);
  $file
    ->save();
  $this
    ->FileUsageAdd($file);
  return $path;
}