You are here

protected function elFinderVolumeDrupal::_save in elFinder file manager 6.2

Same name and namespace in other branches
  1. 8.2 src/Controller/elFinderVolumeDrupal.php \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. * *

Parameters

resource $fp file pointer: * @param string $dir target dir path * @param string $name file name * @return bool|string * @author Dmitry (dio) Levashov, Alexey Sukhotin *

File

inc/elfinder.drupalfs.driver.inc, line 258

Class

elFinderVolumeDrupal
elFinder driver for Drupal 6 filesystem.

Code

protected function _save($fp, $dir, $name, $stat) {
  $tmpname = $name;
  $bu_ret = module_invoke_all('elfinder_beforeupload', array(
    'name' => $name,
    'dir' => $dir,
    'stat' => $stat,
  ));
  if (isset($bu_ret)) {
    if (!is_array($bu_ret)) {
      $bu_ret = array(
        $bu_ret,
      );
    }
    $newname = end($bu_ret);
    if (!empty($newname)) {
      $tmpname = $newname;
    }
  }
  $path = $dir . DIRECTORY_SEPARATOR . $tmpname;
  if (!$this
    ->CheckUserQuota()) {
    return false;
  }
  if (!$this
    ->CheckFolderCount($dir)) {
    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);
  $this
    ->DrupalDBAddFile($file);
  return $path;
}