示例#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
 public function Show()
 {
     if (!(bool) $this->Params->get("uploaddisplay")) {
         return "";
     }
     $id = $this->GetId();
     $action = JRoute::_("index.php?option=" . $GLOBALS["com_name"] . "&view=loader" . "&owner=" . $this->Application->owner . "&id=" . $this->Application->oid . "&bid=" . $this->Application->bid . "&root=none" . "&filename=none" . "&type=uploader");
     $label = "";
     $span = "";
     if ((bool) $this->Params->get("labelsdisplay")) {
         $label = '<label class="control-label">' . $this->Params->get('upload') . '</label>';
     } else {
         $span = '<span class="help-block">' . $this->Params->get('upload') . '</span>';
     }
     $result = '<div class="control-group">' . $label . '<div class="controls">' . $span . '<div id="b2jupload_' . $id . '"></div>' . '<span class="help-block">' . JText::_($GLOBALS["COM_NAME"] . '_FILE_SIZE_LIMIT') . " " . $this->human_readable($this->Params->get("uploadmax_file_size") * 1024) . '</span>' . '</div>' . "<script language=\"javascript\" type=\"text/javascript\">" . "jQuery(document).ready(function () {" . "if (typeof Joomla == 'undefined')" . "{" . "\tJoomla = {};" . "\tJoomla.JText =" . "\t{" . "\t\tstrings:{}," . "\t\t'_':function (key, def)" . "\t\t{" . "\t\t\treturn typeof this.strings[key.toUpperCase()] !== 'undefined' ? this.strings[key.toUpperCase()] : def;" . "\t\t}," . "\t\tload:function (object)" . "\t\t{" . "\t\t\tfor (var key in object)" . "\t\t\t{" . "\t\t\t\tthis.strings[key.toUpperCase()] = object[key];" . "\t\t\t}" . "\t\t\treturn this;" . "\t\t}" . "\t};" . "}" . "Joomla.JText.load(" . "{" . "\"COM_B2JCONTACT_BROWSE_FILES\":'" . $this->Params->get("upload_btn") . "'," . "\"JCANCEL\":'" . JText::_("JCANCEL") . "'," . "\"COM_B2JCONTACT_FAILED\":'" . JText::_("COM_B2JCONTACT_FAILED") . "'," . "\"COM_B2JCONTACT_SUCCESS\":'" . JText::_("COM_B2JCONTACT_SUCCESS") . "'," . "\"COM_B2JCONTACT_NO_RESULTS_MATCH\":'" . JText::_("COM_B2JCONTACT_NO_RESULTS_MATCH") . "'" . "}" . ");" . "CreateUploadButton('b2jupload_{$id}', '{$action}', " . $this->Application->b2jcomid . ", " . $this->Application->b2jmoduleid . ", '" . $this->Application->owner . "', " . $this->Application->oid . ");" . "ResetBind('{$id}', " . $this->Application->bid . ", " . $this->Application->b2jcomid . ", " . $this->Application->b2jmoduleid . ", '" . $this->Application->owner . "');" . "});" . "</script>" . '<noscript>' . '<input ' . 'type="file" ' . 'name="b2jstdupload"' . " />" . '</noscript>' . "</div>" . PHP_EOL;
     $jsession = JFactory::getSession();
     $b2jsession = new B2JSession($jsession->getId(), $this->Application->b2jcomid, $this->Application->b2jmoduleid, $this->Application->bid);
     $data = $b2jsession->Load('filelist');
     if ($data) {
         $filelist = explode("|", $data);
     } else {
         $filelist = array();
     }
     $result .= '<div class="control-group">';
     if ($this->Params->get("labelsdisplay") == 1) {
         $result .= '<label class="control-label"></label>';
     }
     $result .= '<div class="controls">';
     $result .= '<ul id="uploadlist-' . $this->Application->owner . $this->Application->oid . '" class="qq-upload-list">';
     foreach ($filelist as &$file) {
         $result .= '<li class="qq-upload-success">' . '<span class="qq-upload-file">' . $this->format_filename(substr($file, 14)) . '</span>' . '<span class="qq-upload-success-text">' . JTEXT::_($GLOBALS["COM_NAME"] . '_SUCCESS') . ' </span>' . '</li>';
     }
     $result .= '</ul>' . PHP_EOL;
     $result .= '<a href="javascript:void(0)" class="" onClick="ResetAttachments(this.parentNode.parentNode.parentNode)">' . $this->Params->get("reset_attachment_btn") . '</a>';
     $result .= '</div>' . '</div>' . PHP_EOL;
     return $result;
 }
示例#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);
 }