protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $matches = array(); if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $type, $matches)) { $name = $uploadFileName = 'clipboard.' . $matches[1]; } else { $uploadFileName = $name; } if (!preg_match($this->options['accept_file_types_lhc'], $uploadFileName)) { $file->error = $this->get_error_message('accept_file_types'); return false; } $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { $fileUpload = new erLhcoreClassModelChatFile(); $fileUpload->size = $file->size; $fileUpload->type = $file->type; $fileUpload->name = $file->name; $fileUpload->date = time(); $fileUpload->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0; $fileUpload->upload_name = $name; $fileUpload->file_path = $this->options['upload_dir']; if (isset($this->options['chat']) && $this->options['chat'] instanceof erLhcoreClassModelChat) { $fileUpload->chat_id = $this->options['chat']->id; } elseif (isset($this->options['online_user']) && $this->options['online_user'] instanceof erLhcoreClassModelChatOnlineUser) { $fileUpload->online_user_id = $this->options['online_user']->id; } $matches = array(); if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $fileUpload->type, $matches)) { $fileUpload->extension = $matches[1]; } else { $partsFile = explode('.', $fileUpload->upload_name); $fileUpload->extension = end($partsFile); } $fileUpload->saveThis(); $file->id = $fileUpload->id; if (isset($this->options['chat']) && $this->options['chat'] instanceof erLhcoreClassModelChat) { // Chat assign $chat = $this->options['chat']; // Format message $msg = new erLhcoreClassModelmsg(); $msg->msg = '[file=' . $file->id . '_' . md5($fileUpload->name . '_' . $fileUpload->chat_id) . ']'; $msg->chat_id = $chat->id; $msg->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0; if ($msg->user_id > 0 && isset($this->options['name_support'])) { $msg->name_support = (string) $this->options['name_support']; } $chat->last_user_msg_time = $msg->time = time(); erLhcoreClassChat::getSession()->save($msg); // Set last message ID if ($chat->last_msg_id < $msg->id) { $chat->last_msg_id = $msg->id; } $chat->has_unread_messages = 1; $chat->updateThis(); } $this->uploadedFile = $fileUpload; } return $file; }
/** * Override the default method to handle the specific things of the download module and * update the database after file was successful uploaded. * This method has the same parameters as the default. * @param $uploaded_file * @param $name * @param $size * @param $type * @param $error * @param $index * @param $content_range * @return stdClass */ protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { global $gPreferences, $gL10n, $gDb, $getId, $gCurrentOrganization, $gCurrentUser; $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (!isset($file->error)) { try { // check filesize against module settings if ($file->size > $gPreferences['max_file_upload_size'] * 1024 * 1024) { throw new AdmException('DOW_FILE_TO_LARGE', $gPreferences['max_file_upload_size']); } // check filename and throw exception if something is wrong admStrIsValidFileName($file->name, true); // get recordset of current folder from database and throw exception if necessary $targetFolder = new TableFolder($gDb); $targetFolder->getFolderForDownload($getId); // now add new file to database $newFile = new TableFile($gDb); $newFile->setValue('fil_fol_id', $targetFolder->getValue('fol_id')); $newFile->setValue('fil_name', $file->name); $newFile->setValue('fil_locked', $targetFolder->getValue('fol_locked')); $newFile->setValue('fil_counter', '0'); $newFile->save(); // Benachrichtigungs-Email für neue Einträge $message = $gL10n->get('DOW_EMAIL_NOTIFICATION_MESSAGE', $gCurrentOrganization->getValue('org_longname'), $file->name, $gCurrentUser->getValue('FIRST_NAME') . ' ' . $gCurrentUser->getValue('LAST_NAME'), date($gPreferences['system_date'], time())); $notification = new Email(); $notification->adminNotfication($gL10n->get('DOW_EMAIL_NOTIFICATION_TITLE'), $message, $gCurrentUser->getValue('FIRST_NAME') . ' ' . $gCurrentUser->getValue('LAST_NAME'), $gCurrentUser->getValue('EMAIL')); } catch (AdmException $e) { $file->error = $e->getText(); unlink($this->options['upload_dir'] . $file->name); return $file; } } return $file; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { $sql = 'INSERT INTO `' . $this->options['db_table'] . '` (`name`, `size`, `type`, `title`, `description`, `empresa`, `cat`, `orden`, `equipo`)' . ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'; $query = $this->db->prepare($sql); $query->bind_param('sisssssss', $file->name, $file->size, $file->type, $file->title, $file->description, $file->empresa, $file->cat, $file->orden, $file->equi_id); $query->execute(); $file->id = $this->db->insert_id; } return $file; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { $sql = 'INSERT INTO `' . $this->options['db_table'] . '` (`imggrafmed_nombre`, `imggrafmed_descripcion`, `imggrafmed_size`, `imggrafmed_type`, `imggrafmed_fechar`, `imggrafmed_orden`, `imggrafmed_configuracion`)' . ' VALUES (?, ?, ?, ?, ?, ?, ?)'; $query = $this->db->prepare($sql); $query->bind_param('sssssss', $file->name, $file->descripcion, $file->size, $file->type, $file->fechar, $file->orden, $file->configuracion); $query->execute(); $file->id = $this->db->insert_id; } return $file; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { $sql = 'INSERT INTO `' . $this->options['db_table'] . '` (`incentivoimg_nombre`, `incentivoimg_incentivo`, `incentivoimg_fechar`, `incentivoimg_horar`, `incentivoimg_descripcion`, `incentivoimg_tipo`, `incentivoimg_tamanio`,`incentivoimg_qregistra`,`incentivoimg_archivo`)' . ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'; $query = $this->db->prepare($sql); $query->bind_param('sisssssis', $file->name, $file->inc, $file->fechar, $file->horar, $file->descripcion, $file->type, $file->size, $file->qregistra, $file->archivox); $query->execute(); $file->id = $this->db->insert_id; } return $file; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { //processo para substituir o nome do arquivo $newname = md5(uniqid(rand(), true)); $name = explode(".", $name); $ext = array_pop($name); $name = trim($newname . '.' . $ext); $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { //busca o id do usuário atual $user_id = $_SESSION['user_id']; //processor para manter apenas uma unica imagem armazenada //inicio $query1 = $this->db->prepare('SELECT `nome` FROM `imagem_perfil_user` WHERE `codigo_user`= ? '); $query1->bind_param('i', $user_id); $query1->execute(); $query1->store_result(); $query1->bind_result($nome); if ($query1->num_rows > 0) { while ($query1->fetch()) { $sql = 'DELETE FROM `' . $this->options['db_table'] . '` WHERE `nome`=?'; $query2 = $this->db->prepare($sql); $query2->bind_param('s', $nome); if ($query2->execute()) { $file_image = 'archives/perfil/' . $user_id . '/' . $nome; if (is_file($file_image)) { unlink($file_image); } $file_thumb = 'archives/perfil/' . $user_id . '/thumbnail/' . $nome; if (is_file($file_thumb)) { unlink($file_thumb); } } } } $sql = 'INSERT INTO `' . $this->options['db_table'] . '` (`codigo_user`, `nome`, `type`, `size`) VALUES (?, ?, ?, ?)'; $query = $this->db->prepare($sql); $query->bind_param('isss', $user_id, $file->name, $file->type, $file->size); $query->execute(); $file->id = $this->db->insert_id; $update_stmt = $this->db->prepare("UPDATE usuario SET foto = ? WHERE codigo = ?"); $update_stmt->bind_param('si', $file->name, $user_id); //s = string pra cada campo - i = inteiro $update_stmt->execute(); //fim } return $file; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { try { $this->flot = new Flot(); $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { $o_ImageProcessor = new ImageProcessor(S_BASE_PATH, S_BASE_EXTENSION . $this->flot->datastore->settings->upload_dir, $file->name); $o_ImageProcessor->process_and_tag_to_datastore(); } else { echo $file->error; } return $file; } catch (Exception $e) { echo $e; } }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { //$new_name = $this->strtolower_utf8($name); //$newfilename = rand(1,99999).end(explode(".",$_FILES["file"]["name"])); $is_image = false; switch ($type) { case 'image/jpeg': case 'image/png': case 'image/gif': $name = str_replace(" ", "_", $name); $new_name = time() . $name; $is_image = true; break; default: $name = str_replace(" ", "_", $name); $new_name = md5(time() . $name); break; } $file = parent::handle_file_upload($uploaded_file, $new_name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { // $db = JFactory::getDbo(); // $jConfig= new JConfig(); // $db->select($jConfig->db); // $user = JFactory::getUser(); if (!$file->type_id) { $file->type_id = -1; } if (!$file->object_id) { $file->object_id = 0; } if (!$file->created_by) { $file->created_by = $user->id; } if (!$file->folder) { $file->folder = 'uploader/files'; } if (!$file->filename) { $file->filename = $name; } $mapper = Core::model('Core/Attachment'); $file->code = $new_name; $formData = array('folder' => $file->folder, 'object_id' => $file->object_id, 'code' => $new_name, 'mime' => $file->type, 'url' => $is_image == false ? $file->url . '&download=1' : $file->url, 'filename' => $name, 'type_id' => $file->type_id, 'created_by' => $file->created_by, 'created_at' => date('Y-m-d H:i:s')); $file->id = $mapper->create($formData); } return $file; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { global $USER; $uid = $USER->GetID(); $rsUser = CUser::GetByID($uid); $arUser = $rsUser->Fetch(); $arFile = CFile::MakeFileArray($_SERVER['DOCUMENT_ROOT'] . "/upload/avatar/thumbnail/" . $file->name); $arFile['del'] = "Y"; $arFile['old_file'] = $arUser['PERSONAL_PHOTO']; $arFile["MODULE_ID"] = "main"; $fields['PERSONAL_PHOTO'] = $arFile; $cuser = new CUser(); $cuser->Update($uid, $fields); } return $file; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { // Delete all files in directory if replace if (@$_POST["replace"] == "1") { $upload_dir = $this->get_upload_path(); if ($ar = glob($upload_dir . "/*.*")) { foreach ($ar as $v) { @unlink($v); } } foreach ($this->options["image_versions"] as $version => $options) { if (!empty($version)) { if ($ar = glob($upload_dir . "/" . $version . "/*.*")) { foreach ($ar as $v) { @unlink($v); } } } } } return parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { //processo para substituir o nome do arquivo if (app_field_get_config("midia-ck-nome-banner")) { $newname = md5(uniqid(rand(), true)); $name = explode(".", $name); $ext = array_pop($name); $name = trim($newname . '.' . $ext); } $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); $url = parent::get_download_url($file->name); $url = $url; if (empty($file->error)) { $ordem = getOrdem(); $sql = 'INSERT INTO `' . $this->options['db_table'] . '` ( `file_name`, `imagem_url`, `ordem`, `publicar`) VALUES (?, ?, ?, \'falso\')'; $query = $this->db->prepare($sql); $query->bind_param('ssi', $file->name, $url, $ordem); $query->execute(); //fim } return $file; }
/** * We add a meta-data file for the upload in the meta dir */ protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null) { $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index); if (is_object($file)) { $file_path = $this->options['upload_dir'] . $file->name; if (is_file($file_path)) { global $wgUser; $desc = jQueryUpload::$desc[$file->name]; $meta = $this->options['upload_dir'] . 'meta/' . $file->name; $data = array($wgUser->getID(), time(), $desc == wfMsg('jqueryupload-enterdesc') ? '' : $desc); file_put_contents($meta, serialize($data)); } } return $file; }
/** * Override the default method to handle the specific things of the photo module and * update the database after file was succesful uploaded. * This method has the same parameters as the default. * @param $uploaded_file * @param $name * @param $size * @param $type * @param $error * @param $index * @param $content_range * @return stdClass */ protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { global $photoAlbum, $gPreferences, $gL10n; $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (!isset($file->error)) { try { $fileLocation = SERVER_PATH . '/adm_my_files/photos/upload/' . $file->name; $albumFolder = SERVER_PATH . '/adm_my_files/photos/' . $photoAlbum->getValue('pho_begin', 'Y-m-d') . '_' . $photoAlbum->getValue('pho_id'); // create folder if not exists if (!file_exists($albumFolder)) { $error = $photoAlbum->createFolder(); if ($error['text'] !== '') { $file->error = $gL10n->get($error['text'], $error['path']); return $file; } } $newFotoFileNumber = $photoAlbum->getValue('pho_quantity') + 1; // read image size $imageProperties = getimagesize($fileLocation); $imageDimensions = $imageProperties[0] * $imageProperties[1]; if ($imageDimensions > admFuncProcessableImageSize()) { $errorText = $gL10n->get('PHO_RESOLUTION_MORE_THAN') . ' ' . round(admFuncProcessableImageSize() / 1000000, 2) . ' ' . $gL10n->get('MEGA_PIXEL'); throw new AdmException($errorText); } // check mime type and set file extension if ($imageProperties['mime'] === 'image/jpeg') { $fileExtension = 'jpg'; } elseif ($imageProperties['mime'] === 'image/png') { $fileExtension = 'png'; } else { throw new AdmException('PHO_PHOTO_FORMAT_INVALID'); } // create image object and scale image to defined size of preferences $image = new Image($fileLocation); $image->setImageType('jpeg'); $image->scaleLargerSide($gPreferences['photo_save_scale']); $image->copyToFile(null, $albumFolder . '/' . $newFotoFileNumber . '.jpg'); $image->delete(); // if enabled then save original image if ($gPreferences['photo_keep_original'] == 1) { if (!file_exists($albumFolder . '/originals')) { $folder = new Folder($albumFolder); $folder->createFolder('originals', true); } rename($fileLocation, $albumFolder . '/originals/' . $newFotoFileNumber . '.' . $fileExtension); } // save thumbnail if (!file_exists($albumFolder . '/thumbnails')) { $folder = new Folder($albumFolder); $folder->createFolder('thumbnails', true); } $image = new Image($fileLocation); $image->scaleLargerSide($gPreferences['photo_thumbs_scale']); $image->copyToFile(null, $albumFolder . '/thumbnails/' . $newFotoFileNumber . '.jpg'); $image->delete(); // delete image from upload folder if (file_exists($fileLocation)) { unlink($fileLocation); } // if image was successfully saved in filesystem then update image count of album if (file_exists($albumFolder . '/' . $newFotoFileNumber . '.jpg')) { $photoAlbum->setValue('pho_quantity', $photoAlbum->getValue('pho_quantity') + 1); $photoAlbum->save(); } else { throw new AdmException('PHO_PHOTO_PROCESSING_ERROR'); } } catch (AdmException $e) { $file->error = $e->getText(); unlink($this->options['upload_dir'] . $file->name); return $file; } } return $file; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $this->security(); $idModelo = $_REQUEST['id_modelo']; $modo = $_REQUEST['modo']; // remplaza el nombre por un id unico $ext = substr($name, strrpos($name, '.') + 1); $name = uniqid() . "." . $ext; //var_dump($name); $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { if ($modo == 'model') { $service = $this->app->modelService; } else { $service = $this->app->obrasService; } $modelo = new stdClass(); $modelo->id = $idModelo; $foto = new stdClass(); $foto->name = $file->name; $foto->foto = $file->url; $foto->thumbnail = $file->thumbnailUrl; $saved = $service->addFoto($modelo, $foto); $file = $saved; } return $file; }