protected function act_upload() { if ($this->config['readonly'] || !isset($this->post['dir'])) { $this->errorMsg("Unknown error."); } $dir = $this->postDir(); if (!dir::isWritable($dir)) { $this->errorMsg("Cannot access or write to upload folder."); } $message = $this->checkUploadedFile(); if ($message !== true) { if (isset($this->file['tmp_name'])) { @unlink($this->file['tmp_name']); } $this->errorMsg($message); } $target = "{$dir}/" . file::getInexistantFilename($this->file['name'], $dir); if (!move_uploaded_file($this->file['tmp_name'], $target)) { @unlink($this->file['tmp_name']); $this->errorMsg("Cannot move uploaded file to target folder."); } elseif (function_exists('chmod')) { chmod($target, $this->config['filePerms']); } $this->makeThumb($target); return "/" . basename($target); }
protected function moveUploadFile($file, $dir) { $message = $this->checkUploadedFile($file); if ($message !== true) { if (isset($file['tmp_name'])) { @unlink($file['tmp_name']); } return "{$file['name']}: {$message}"; } // $filename = $this->normalizeFilename($file['name']); $filename = md5($file['tmp_name']) . '.' . file::getExtension($file['name']); $target = "{$dir}/" . file::getInexistantFilename($filename, $dir); if (!@move_uploaded_file($file['tmp_name'], $target) && !@rename($file['tmp_name'], $target) && !@copy($file['tmp_name'], $target)) { @unlink($file['tmp_name']); return "{$file['name']}: " . $this->label("Cannot move uploaded file to target folder."); } elseif (function_exists('chmod')) { chmod($target, $this->config['filePerms']); } $this->makeThumb($target); return "/" . basename($target); }
public function upload() { $config =& $this->config; $file =& $this->file; $url = $message = ""; if ($config['disabled'] || !$config['access']['files']['upload']) { if (isset($file['tmp_name'])) { @unlink($file['tmp_name']); } $message = $this->label("You don't have permissions to upload files."); } elseif (true === ($message = $this->checkUploadedFile())) { $message = ""; $dir = "{$this->typeDir}/"; if (isset($_GET['dir']) && false !== ($gdir = $this->checkInputDir($_GET['dir']))) { $udir = path::normalize("{$dir}{$gdir}"); if (substr($udir, 0, strlen($dir)) !== $dir) { $message = $this->label("Unknown error."); } else { $l = strlen($dir); $dir = "{$udir}/"; $udir = substr($udir, $l); } } if (!strlen($message)) { if (!is_dir(path::normalize($dir))) { @mkdir(path::normalize($dir), $this->config['dirPerms'], true); } $filename = $this->normalizeFilename($file['name']); $target = file::getInexistantFilename($dir . $filename); if (!@move_uploaded_file($file['tmp_name'], $target) && !@rename($file['tmp_name'], $target) && !@copy($file['tmp_name'], $target)) { $message = $this->label("Cannot move uploaded file to target folder."); } else { if (function_exists('chmod')) { @chmod($target, $this->config['filePerms']); } $target = $this->checkUploadedFileMime($target); // fix the target ... $this->makeThumb($target); $url = $this->typeURL; if (isset($udir)) { $url .= "/{$udir}"; } $url .= "/" . basename($target); if (preg_match('/^([a-z]+)\\:\\/\\/([^\\/^\\:]+)(\\:(\\d+))?\\/(.+)$/', $url, $patt)) { list($unused, $protocol, $domain, $unused, $port, $path) = $patt; $base = "{$protocol}://{$domain}" . (strlen($port) ? ":{$port}" : "") . "/"; $url = $base . path::urlPathEncode($path); } else { $url = path::urlPathEncode($url); } } } } if (strlen($message) && isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) { @unlink($this->file['tmp_name']); } if (strlen($message) && method_exists($this, 'errorMsg')) { $this->errorMsg($message); } else { $this->callBack($url, $message); } }
protected function moveUploadFile($file, $dir) { $message = $this->checkUploadedFile($file); if ($message !== true) { if (isset($file['tmp_name'])) { @unlink($file['tmp_name']); } return "{$file['name']}: {$message}"; } $filename = $this->normalizeFilename($file['name']); $target = "{$dir}/" . file::getInexistantFilename($filename, $dir); if (!@move_uploaded_file($file['tmp_name'], $target) && !@rename($file['tmp_name'], $target) && !@copy($file['tmp_name'], $target)) { @unlink($file['tmp_name']); return "{$file['name']}: " . $this->label("Cannot move uploaded file to target folder."); } elseif (function_exists('chmod')) { chmod($target, $this->config['filePerms']); } $this->modx->invokeEvent('OnFileBrowserUpload', array('filepath' => realpath($dir), 'filename' => str_replace("/", "", str_replace($dir, "", realpath($target))))); $this->makeThumb($target); return "/" . basename($target); }
public function upload() { $config =& $this->config; $file =& $this->file; $url = $message = ""; if ($config['disabled'] || $config['readonly']) { if (isset($file['tmp_name'])) { @unlink($file['tmp_name']); } $message = $this->label("You don't have permissions to upload files."); } elseif (true === ($message = $this->checkUploadedFile())) { $message = ""; $dir = "{$this->typeDir}/"; if (isset($this->get['dir']) && false !== ($gdir = $this->checkInputDir($this->get['dir']))) { $udir = path::normalize("{$dir}{$gdir}"); if (substr($udir, 0, strlen($dir)) !== $dir) { $message = $this->label("Unknown error."); } else { $l = strlen($dir); $dir = "{$udir}/"; $udir = substr($udir, $l); } } if (!strlen($message)) { if (!is_dir(path::normalize($dir))) { @mkdir(path::normalize($dir), $this->config['dirPerms'], true); } $target = file::getInexistantFilename("{$dir}{$file['name']}"); if (!@move_uploaded_file($file['tmp_name'], $target) && !@rename($file['tmp_name'], $target) && !@copy($file['tmp_name'], $target)) { $message = $this->label("Cannot move uploaded file to target folder."); } else { if (function_exists('chmod')) { @chmod($target, $this->config['filePerms']); } $this->makeThumb($target); $url = $this->typeURL; if (isset($udir)) { $url .= "/{$udir}"; } $url .= "/" . basename($target); $url = path::urlPathEncode($url); } } } if (strlen($message) && isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) { @unlink($this->file['tmp_name']); } if (strlen($message) && method_exists($this, 'errorMsg')) { $this->errorMsg($message); } $this->callBack($url, $message); }
protected function moveUploadFile($file, $dir) { $message = $this->checkUploadedFile($file); if ($message !== true) { if (isset($file['tmp_name'])) { @unlink($file['tmp_name']); } return "{$file['name']}: {$message}"; } $filename = $this->normalizeFilename($file['name']); $target = "{$dir}/" . file::getInexistantFilename($filename, $dir); if (!@move_uploaded_file($file['tmp_name'], $target) && !@rename($file['tmp_name'], $target) && !@copy($file['tmp_name'], $target)) { @unlink($file['tmp_name']); return "{$file['name']}: " . $this->label("Cannot move uploaded file to target folder."); } elseif (function_exists('chmod')) { chmod($target, $this->config['filePerms']); } $this->makeThumb($target); if (isset($this->config['extraThumbnails'])) { foreach ($this->config['extraThumbnails'] as $a) { // Hack the config values to trick the thumbnail // creator; FIXME: fork the makeThumb method and // remove this ugly hack $this->config['thumbWidth'] = $a['thumbWidth']; $this->config['thumbHeight'] = $a['thumbHeight']; // Define the suffix used in file names, // e.g. DSC82347_300x200.png $suffix = '_' . $a['thumbWidth'] . 'x' . $a['thumbHeight']; $this->makeThumb($target, true, $suffix); } } return "/" . basename($target); }
public function upload() { $config =& $this->config; $file =& $this->file; $url = $message = ""; if ($config['disabled'] || !$config['access']['files']['upload']) { if (isset($file['tmp_name'])) { @unlink($file['tmp_name']); } $message = $this->label("You don't have permissions to upload files."); } elseif (true === ($message = $this->checkUploadedFile())) { $message = ""; $dir = "{$this->typeDir}/"; if (isset($this->get['dir']) && false !== ($gdir = $this->checkInputDir($this->get['dir']))) { $udir = path::normalize("{$dir}{$gdir}"); if (substr($udir, 0, strlen($dir)) !== $dir) { $message = $this->label("Unknown error."); } else { $l = strlen($dir); $dir = "{$udir}/"; $udir = substr($udir, $l); } } if (!strlen($message)) { if (!is_dir(path::normalize($dir))) { @mkdir(path::normalize($dir), $this->config['dirPerms'], true); } $filename = $this->normalizeFilename($file['name']); $target = file::getInexistantFilename($dir . $filename); if (!@move_uploaded_file($file['tmp_name'], $target) && !@rename($file['tmp_name'], $target) && !@copy($file['tmp_name'], $target)) { $message = $this->label("Cannot move uploaded file to target folder."); } else { if (function_exists('chmod')) { @chmod($target, $this->config['filePerms']); } $this->makeThumb($target); if (isset($this->config['extraThumbnails'])) { die('entered!'); foreach ($this->config['extraThumbnails'] as $a) { // Hack the config values to trick the thumbnail // creator; FIXME: fork the makeThumb method and // remove this ugly hack $this->config['thumbWidth'] = $a['thumbWidth']; $this->config['thumbHeight'] = $a['thumbHeight']; // Define the suffix used in file names, // e.g. DSC82347_300x200.png $suffix = '_' . $a['thumbWidth'] . 'x' . $a['thumbHeight']; $this->makeThumb($target, true, $suffix); } } if ($this->config['read_exif'] == true) { $exif = exif_read_data($target, 'IFD0'); file_put_contents(json_encode($exif), '/tmp/exif'); } $url = $this->typeURL; if (isset($udir)) { $url .= "/{$udir}"; } $url .= "/" . basename($target); if (preg_match('/^([a-z]+)\\:\\/\\/([^\\/^\\:]+)(\\:(\\d+))?\\/(.+)$/', $url, $patt)) { list($unused, $protocol, $domain, $unused, $port, $path) = $patt; $base = "{$protocol}://{$domain}" . (strlen($port) ? ":{$port}" : "") . "/"; $url = $base . path::urlPathEncode($path); } else { $url = path::urlPathEncode($url); } } } } if (strlen($message) && isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) { @unlink($this->file['tmp_name']); } if (strlen($message) && method_exists($this, 'errorMsg')) { $this->errorMsg($message); } $this->callBack($url, $message); }