/** * Get the File Browser instance * @access public * @return object WFBrowserExtension */ public function getBrowser() { static $browser; if (!is_object($browser)) { $browser = WFFileBrowser::getInstance($this->getProperties()); } return $browser; }
public function upload($method = 'multipart', $src, $dir, $name, $chunks = 1, $chunk = 0) { jimport('joomla.filesystem.file'); $path = WFUtility::makePath($this->getBaseDir(), rawurldecode($dir)); $dest = WFUtility::makePath($path, $name); // check for safe mode $safe_mode = false; if (function_exists('ini_get')) { $safe_mode = ini_get('safe_mode'); } else { $safe_mode = true; } $result = new WFFileSystemResult(); // get overwrite state $conflict = $this->get('upload_conflict', 'overwrite'); // get suffix $suffix = WFFileBrowser::getFileSuffix(); switch ($method) { case 'multipart': if ($conflict == 'unique') { // get extension $extension = JFile::getExt($name); // get name without extension $name = JFile::stripExt($name); while (JFile::exists($dest)) { $name .= $suffix; $dest = WFUtility::makePath($path, $name . '.' . $extension); } } if (JFile::upload($src, $dest)) { $result->state = true; $result->path = $dest; } break; case 'multipart-chunking': if ($safe_mode || !is_writable(dirname($dest))) { $result->message = WFText::_('WF_MANAGER_UPLOAD_NOSUPPORT'); $result->code = 103; } else { if ($chunk == 0 && $overwrite) { // get extension $extension = JFile::getExt($name); // get name without extension $name = JFile::stripExt($name); // make unique file name while (JFile::exists($dest)) { $name .= $suffix; $dest = WFUtility::makePath($path, $name . '.' . $extension); } } $out = fopen($dest, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen($src, "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } fclose($in); fclose($out); @unlink($src); $result->state = true; if ($chunk == $chunks - 1) { if (is_file($dest)) { $result->path = $dest; } } } else { $result->code = 102; $result->message = 'UPLOAD_INPUT_STREAM_ERROR'; } } else { $result->code = 102; $result->message = 'UPLOAD_OUTPUT_STREAM_ERROR'; } } break; case 'stream': if ($safe_mode || !is_writable(dirname($dest))) { $result->message = WFText::_('WF_MANAGER_UPLOAD_NOSUPPORT'); } else { // Open destination file $out = fopen($dest, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } if (fclose($out) && is_file($dest)) { $result->state = true; $result->path = $dest; } } } } break; } return $result; }
public function upload($method = 'multipart', $src, $dir, $name, $chunks = 1, $chunk = 0) { jimport('joomla.filesystem.file'); $path = WFUtility::makePath($this->getBaseDir(), rawurldecode($dir)); $dest = WFUtility::makePath($path, $name); // check for safe mode $safe_mode = false; if (function_exists('ini_get')) { $safe_mode = ini_get('safe_mode'); } else { $safe_mode = true; } $result = new WFFileSystemResult(); // get overwrite state $conflict = $this->get('upload_conflict', 'overwrite'); // get suffix $suffix = WFFileBrowser::getFileSuffix(); if ($conflict == 'unique') { // get extension $extension = JFile::getExt($name); // get name without extension $name = JFile::stripExt($name); while (JFile::exists($dest)) { $name .= $suffix; $dest = WFUtility::makePath($path, $name . '.' . $extension); } } if (JFile::upload($src, $dest, false, true)) { $result->state = true; $result->path = $dest; } return $result; }