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); }
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); } }
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); }