示例#1
0
 protected function DoUpload()
 {
     $file = JRequest::getVar('b2jstdupload', NULL, 'files', 'array');
     if (!$this->Submitted || !$file || $file['error'] == UPLOAD_ERR_NO_FILE) {
         return true;
     }
     $upload_directory = JPATH_SITE . "/components/" . $GLOBALS["com_name"] . "/uploads/";
     if (!is_writable($upload_directory)) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_DIR_NOT_WRITABLE'), B2JMessageBoard::error);
         return false;
     }
     if ($file['error']) {
         $this->MessageBoard->Add(JText::sprintf($GLOBALS["COM_NAME"] . '_ERR_UPLOAD', $file['error']), B2JMessageBoard::error);
         return false;
     }
     $size = $file['size'];
     if ($size == 0) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_FILE_EMPTY'), B2JMessageBoard::error);
         return false;
     }
     $max_filesize = intval($this->Params->get("uploadmax_file_size", "0")) * KB;
     if ($size > $max_filesize) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_FILE_TOO_LARGE'), B2JMessageBoard::error);
         return false;
     }
     $mimetype = new B2JMimeType();
     if (!$mimetype->Check($file['tmp_name'], $this->Params)) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_MIME') . " [" . $mimetype->Mimetype . "]", B2JMessageBoard::error);
         return false;
     }
     jimport('joomla.filesystem.file');
     $filename = JFile::makeSafe($file['name']);
     $filename = uniqid() . "-" . $filename;
     $dest = $upload_directory . $filename;
     if (!JFile::upload($file['tmp_name'], $dest)) {
         return false;
     }
     $jsession =& JFactory::getSession();
     $b2jsession = new B2JSession($jsession->getId(), $this->Application->b2jcomid, $this->Application->b2jmoduleid, $this->Application->bid);
     // session_id, cid, mid
     $data = $b2jsession->Load('filelist');
     if ($data) {
         $filelist = explode("|", $data);
     } else {
         $filelist = array();
     }
     $filelist[] = $filename;
     $data = implode("|", $filelist);
     $b2jsession->Save($data, "filelist");
     return true;
 }
示例#2
0
文件: captcha.php 项目: grlf/eyedock
 public function Draw()
 {
     $jsession = JFactory::getSession();
     $b2jcomid = $b2jmoduleid = 0;
     switch (JFactory::getApplication()->input->get("owner", NULL)) {
         case "component":
             $b2jcomid = JFactory::getApplication()->input->get("id", NULL);
             break;
         case "module":
             $b2jmoduleid = JFactory::getApplication()->input->get("id", NULL);
     }
     $bid = JFactory::getApplication()->input->get("bid", NULL);
     $b2jsession = new B2JSession($jsession->getId(), $b2jcomid, $b2jmoduleid, $bid);
     if ($b2jsession->Save($this->Answer, "captcha_answer")) {
         $this->DebugLog->Write("Answer saved into session");
     } else {
         $this->DebugLog->Write("Database query failed");
     }
     imagefill($this->Image['data'], 0, 0, $this->Colors['Background']);
     $this->DrawGrid();
     $len = strlen($this->Question);
     $space = $this->Image['width'] / $len;
     for ($p = 0; $p < 2 * $len; ++$p) {
         $this->Render(chr(rand(33, 126)), $p, $space / 2, $this->Colors['Disturb']);
     }
     for ($p = 0; $p < $len; ++$p) {
         $this->Render($this->Question[$p], $p, $space, $this->Colors['Text']);
     }
     $this->DebugLog->Write("Render done");
     if (JFactory::getApplication()->input->get("noimage", NULL)) {
         return;
     }
     header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     header("Content-Type:image/jpeg");
     header("Content-Disposition:inline ; filename=b2jcaptcha.jpg");
     imagejpeg($this->Image['data']);
     imagedestroy($this->Image['data']);
     $this->DebugLog->Write("Image sent to client");
 }
示例#3
0
文件: uploader.php 项目: grlf/eyedock
 public function HandleUpload($uploadDirectory)
 {
     $this->DebugLog->Write("HandleUpload() started");
     if (!is_writable($uploadDirectory)) {
         $this->DebugLog->Write("Directory " . $uploadDirectory . " is not writable");
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_DIR_NOT_WRITABLE'));
     }
     $this->DebugLog->Write("Directory " . $uploadDirectory . " is ok");
     $size = $this->get_file_size();
     if ($size == 0) {
         $this->DebugLog->Write("File size is 0");
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_FILE_EMPTY'));
     }
     $this->DebugLog->Write("File size is > 0");
     $max = $this->Params->get("uploadmax_file_size", 0) * KB;
     if ($size > $max) {
         $this->DebugLog->Write("File size too large ({$size} > {$max})");
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_FILE_TOO_LARGE'));
     }
     $this->DebugLog->Write("File size ({$size} / {$max}) is ok");
     $filename = preg_replace("/[^\\w\\.-_]/", "_", $this->get_file_name());
     $filename = uniqid() . "-" . $filename;
     $full_filename = $uploadDirectory . $filename;
     if (!$this->save_file($full_filename)) {
         $this->DebugLog->Write("Error saving file");
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_SAVE_FILE'));
     }
     $this->DebugLog->Write("File saved");
     $mimetype = new B2JMimeType();
     if (!$mimetype->Check($full_filename, $this->Params)) {
         unlink($full_filename);
         $this->DebugLog->Write("File type [" . $mimetype->Mimetype . "] is not allowed. Allowed types are:" . PHP_EOL . print_r($mimetype->Allowed, true));
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_MIME') . " [" . $mimetype->Mimetype . "]");
     }
     $this->DebugLog->Write("File type [" . $mimetype->Mimetype . "] is allowed");
     $b2jcomid = JFactory::getApplication()->input->get("b2jcomid", NULL);
     $b2jmoduleid = JFactory::getApplication()->input->get("b2jmoduleid", NULL);
     $owner = JFactory::getApplication()->input->get("owner", NULL);
     $id = JFactory::getApplication()->input->get("id", NULL);
     $bid = JFactory::getApplication()->input->get("bid", NULL);
     $jsession = JFactory::getSession();
     $b2jsession = new B2JSession($jsession->getId(), $b2jcomid, $b2jmoduleid, $bid);
     $data = $b2jsession->Load('filelist');
     if ($data) {
         $filelist = explode("|", $data);
     } else {
         $filelist = array();
     }
     $filelist[] = $filename;
     $data = implode("|", $filelist);
     $b2jsession->Save($data, "filelist");
     $this->Log->Write("File " . $filename . " uploaded succesful.");
     $this->DebugLog->Write("File uploaded succesful.");
     return array("success" => true);
 }