/** * @desc sube una imagen jpg al servidor * @param void * @return void */ private function imgUpload() { $msg = ""; $dir = IMG_LOCAL_PATH . "eventos/" . $this->_event_id; $dirweb = IMG_WEB_PATH . "eventos/" . $this->_event_id; $handle = new Upload($_FILES['urlfoto']); if ($handle->uploaded) { // movemos de temp a dir final $handle->Process($dir); // we check if everything went OK if ($handle->processed) { // everything was fine ! $msg .= '!Carga exitosa!: <a href="' . $dirweb . '/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>'; } else { // one error occured $msg .= '<fieldset>'; $msg .= ' <legend>No es posible mover la imagen en la ruta indicada</legend>'; $msg .= ' Error: ' . $handle->error . ''; $msg .= '</fieldset>'; } // we delete the temporary files $handle->Clean(); } else { // if we're here, the upload file failed for some reasons // i.e. the server didn't receive the file $msg .= '<fieldset>'; $msg .= ' <legend>No es pposible cargar la imagen al servidor.</legend>'; $msg .= ' Error: ' . $handle->error . ''; $msg .= '</fieldset>'; } return $msg; }
return $this->db->lastInsertId(); } /** * Update image */ public function updateImage($id) { $ruler = new Ruler($id); if ($ruler->Background == null) { return false; } require_once 'core/class.upload/class.upload.php'; $templates = DIR_DBIMAGES . 'ruler/templates/'; $results = DIR_DBIMAGES . 'ruler/results/'; $iu = new Upload($templates . $ruler->Background); $iu->file_overwrite = true; $iu->file_new_name_body = $id; $iu->file_new_name_ext = 'jpg'; $iu->image_unsharp = true; $iu->image_border = '0 0 16 0'; $iu->image_border_color = strtolower($ruler->Color) == '#ffffff' ? '#333333' : '#ffffff'; $iu->image_watermark = $templates . $ruler->Slider; $iu->image_watermark_y = 35; $iu->image_watermark_x = $ruler->getSliderPosition(); $iu->Process($results); $image = imagecreatefromjpeg($results . $id . '.jpg');
function asignar_cotizacion($id_equipo, $placa_inventario) { App::import('Vendor', 'upload', array('file' => 'class.upload.php')); $this->autoLayout = false; $this->autoRender = false; $datos_json = array('resultado' => false, 'id' => '', 'nombre_archivo' => ''); if (!empty($_FILES) && !empty($id_equipo) && !empty($placa_inventario)) { if (!empty($_FILES['cotizacion']['name'])) { $handle = new Upload($_FILES['cotizacion']); if ($handle->uploaded) { $handle->file_overwrite = true; $handle->file_safe_name = false; $handle->file_auto_rename = false; $handle->file_new_name_body = 'cotizacion(' . $this->Cotizacion->getNextAutoIncrement() . ')_' . $placa_inventario; $handle->Process('equipos/cotizaciones'); if ($handle->processed) { $this->data['Cotizacion']['nombre_archivo'] = $handle->file_dst_name; $this->data['Cotizacion']['id_equipo'] = $id_equipo; $this->data['Cotizacion']['placa_inventario'] = $placa_inventario; if ($this->Cotizacion->save($this->data)) { $datos_json['resultado'] = true; $datos_json['id'] = $this->Cotizacion->id; $datos_json['nombre_archivo'] = $this->data['Cotizacion']['nombre_archivo']; } } $handle->Clean(); } } } return json_encode($datos_json); }
public function __construct($feed, $type) { $this->feedArray = $feed; $this->feedType = $type; $this->size = '1000000'; $maxSize = $this->size / 1000000; if ($this->feedType == 'text') { $this->feedText = $feed; } else { if ($this->feedType == 'img') { $this->feedImg = $feed['image']; $this->feedText = $feed['text']; $this->newName = $_SESSION['isv_user_id'] . str_replace(' ', '', microtime()); $this->newName = str_replace('.', '', $this->newName); $path = ISVIPI_UPLOADS_BASE . 'feeds/'; //check file size if ($this->feedImg["size"] > $this->size) { $array['err'] = true; $array['message'] = 'The file is too large. Maximum file size is ' . $maxSize . ' MB.'; echo json_encode($array); exit; } //check file type if ($this->feedImg["type"] != "image/jpg" && $this->feedImg["type"] != "image/png" && $this->feedImg["type"] != "image/jpeg" && $this->feedImg["type"] != "image/gif") { $array['err'] = true; $array['message'] = 'Allowed file types are .jpg .jpeg .png .gif'; echo json_encode($array); exit; } //require file upload class require_once ISVIPI_CLASSES_BASE . 'utilities/class.upload.php'; $newUpload = new Upload($this->feedImg); $newUpload->file_new_name_body = ISVIPI_600 . $this->newName; $newUpload->image_resize = true; $newUpload->image_convert = 'jpg'; $newUpload->image_x = 600; $newUpload->image_ratio_y = true; $newUpload->Process($path); if (!$newUpload->processed) { $array['err'] = true; $array['message'] = 'An error occurred: ' . $newUpload->error . ''; echo json_encode($array); exit; } $newUpload->Clean(); } } /** add our feed to the database **/ $this->addFeed(); /** return success **/ $array['err'] = false; echo json_encode($array); exit; }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $model = $this->getModel('admanager'); $data = $model->getFile($post['id']); if (isset($_FILES['file_upload'])) { $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { $dir = HOTELGUIDE_IMAGES_BANNER . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['filename'] = $handle->file_dst_name; $post['imagewidth'] = $width; $post['imageheight'] = $height; $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=admanager&cid[]=' . (int) $model->get('id'); break; default: $link = 'index.php?option=com_hotelguide&view=admanagers'; break; } $msg = JText::_('HG_AD_ITEM_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_ITEM'); JError::raiseError(500, $model->getError()); $link = 'index.php?option=com_hotelguide&view=admanager'; } $model->checkin(); $this->setRedirect($link, $msg); }
public static function add($f) { $foo = new Upload($f); if ($foo->uploaded) { $foo->Process(TMPFILES); } if ($foo->processed) { $fname = $foo->file_src_name_body; $fpath = TMPFILES . DS . $fname; $zip = new ZipArchive(); $res = $zip->open(TMPFILES . DS . $foo->file_src_name); if ($res === TRUE) { $zip->extractTo($fpath . DS); $zip->close(); $pack = json_decode(file_get_contents($fpath . DS . 'package.json'), true); if (count($pack['controllers']) > 0) { foreach ($pack['controllers'] as $c) { File::copy($fpath . DS . 'controllers' . DS . $c, CONTROLLERS . DS . $c); } } if (count($pack['views']) > 0) { foreach ($pack['views'] as $c) { File::copy($fpath . DS . 'views' . DS . $c, VIEWS . DS . $c); } } if (count($pack['langs']) > 0) { foreach ($pack['langs'] as $c) { File::copy($fpath . DS . 'lang' . DS . $c, LANGS . DS . $c); } } if (count($pack['libs']) > 0) { foreach ($pack['libs'] as $c) { File::copy($fpath . DS . 'lib' . DS . $c, LIB . DS . $c); } } if (count($pack['filters']) > 0) { foreach ($pack['filters'] as $c) { File::copy($fpath . DS . 'filters' . DS . $c, FILTER . DS . $c); } } File::copy($fpath . DS . 'package.json', CONFPLUGINS . DS . $pack['name'] . '.json'); File::copy($fpath . DS . 'routes.php', ROOT . DS . "routes" . DS . $pack['name'] . '.routes.php'); File::removedir($fpath); File::remove(TMPFILES . DS . $foo->file_src_name); } else { return false; } } return true; }
/** * save a record (and redirect to main page) * @return void */ function save() { JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $post = JRequest::get('post'); $file = JRequest::getVar('file_upload', '', 'files', 'array'); $task = JRequest::getVar('task'); $model =& $this->getModel('facility'); $filename = ''; if (isset($_FILES['file_upload'])) { $filename = $_FILES['file_upload']['name']; $post['pictogram'] = $filename; $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { $dir = HOTELGUIDE_IMAGES_PICTOGRAM . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($dir); $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=facility&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=facility'; break; default: $link = 'index.php?option=com_hotelguide&view=facilities'; break; } $msg = JText::_('HG_FACILITY_SAVED'); } else { $link = 'index.php?option=com_hotelguide&view=facilities'; $msg = JText::_('HG_ERROR_SAVING_FACILITY'); } $this->setRedirect($link, $msg); }
public function upload($curso_id) { $msg = false; $handle = new Upload($_FILES['agenda']); if ($handle->uploaded) { $handle->Process('files'); if ($handle->processed) { rename(FILES_PATH . $handle->file_dst_name, FILES_PATH . $curso_id . ".pdf"); return 1; } else { $msg = $handle->error; } $handle->Clean(); } else { $msg = $handle->error; } return $msg; }
function createUserPicture($userPicture) { $user_picture_name = $_SESSION['uuID']; $userPicture = new Upload($_FILES['user_image']); if ($userPicture->uploaded) { $userPicture->file_new_name_body = $user_picture_name; $userPicture->image_resize = true; $userPicture->image_x = 300; $userPicture->image_ratio_y = true; $userPicture->file_overwrite = true; $userPicture->image_convert = 'png'; // save uploaded image with no changes $userPicture->Process('../profileImg'); if ($userPicture->processed) { echo 'original image copied'; } else { echo 'error : ' . $foo->error; } } }
public static function newUploadFile($archivoSubir, $rutaGuardarArchivo = 'UploadedFiles') { //Crea Una Nueva Instancia de la clase de subir archivos. $archivo = new Upload($archivoSubir, 'es_ES'); // Verificamos si se puede subir el archivo if ($archivo->uploaded) { //Le damos un nuevo nombre al archivo para que no se duplique. $nuevoNombre = date('HMs') . "_" . $archivo->file_src_name_body; $archivo->file_new_name_body = $nuevoNombre; //Subimos el archivo a la ruta dada ($rutaGuardarArchivo). $archivo->Process($rutaGuardarArchivo); //Verificamos si subio if ($archivo->processed) { echo "Archivo Subido"; //Obtenemos la extension del archivo Subido $extension = $archivo->file_src_name_ext; return $nuevoNombre . "." . $extension; } $archivos->Clean(); } else { echo "Error al subir el archivo..." . $archivo->error; return NULL; } }
/** * Munka kategória képet méretezi és tölti fel a szerverre (thumb képet is) * (ez a metódus a category_insert() metódusban hívódik meg!) * * @param $files_array Array ($_FILES['valami']) * @return String (kép elérési útja) or false */ private function upload_job_category_photo($files_array) { include LIBS . "/upload_class.php"; // feltöltés helye $imagePath = Config::get('jobphoto.upload_path'); //képkezelő objektum létrehozása (a kép a szerveren a tmp könyvtárba kerül) $handle = new Upload($files_array); // fájlneve utáni random karakterlánc $suffix = md5(uniqid()); //file átméretezése, vágása, végleges helyre mozgatása if ($handle->uploaded) { // kép paramétereinek módosítása $handle->file_auto_rename = true; $handle->file_safe_name = true; $handle->allowed = array('image/*'); $handle->file_new_name_body = "jobcategory_" . $suffix; $handle->image_resize = true; $handle->image_x = Config::get('jobphoto.width', 300); //jobphoto kép szélessége $handle->image_y = Config::get('jobphoto.height', 200); //jobphoto kép magassága //$handle->image_ratio_y = true; //képarány meghatározása a nézőképhez $ratio = $handle->image_x / $handle->image_y; // Slide kép készítése $handle->Process($imagePath); if ($handle->processed) { //kép elérési útja és új neve (ezzel tér vissza a metódus, ha nincs hiba!) //$dest_imagePath = $imagePath . $handle->file_dst_name; //a kép neve (ezzel tér vissza a metódus, ha nincs hiba!) $image_name = $handle->file_dst_name; } else { Message::set('error', $handle->error); return false; } // Nézőkép készítése //nézőkép nevének megadása (kép új neve utána _thumb) $handle->file_new_name_body = $handle->file_dst_name_body; $handle->file_name_body_add = '_thumb'; $handle->image_resize = true; $handle->image_x = Config::get('jobphoto.thumb_width', 80); //jobphoto nézőkép szélessége $handle->image_y = round($handle->image_x / $ratio); //$handle->image_ratio_y = true; $handle->Process($imagePath); if ($handle->processed) { //temp file törlése a szerverről $handle->clean(); } else { Message::set('error', $handle->error); return false; } } else { // Message::set('error', $handle->error); return false; } // ha nincs hiba visszadja a feltöltött kép elérési útját return $image_name; }
function save() { $mainframe = JFactory::getApplication(); jimport('joomla.filesystem.file'); require_once JPATH_COMPONENT . DS . 'lib' . DS . 'class.upload.php'; $row = JTable::getInstance('K2Category', 'Table'); $params = JComponentHelper::getParams('com_k2'); if (!$row->bind(JRequest::get('post'))) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=categories'); } $isNew = $row->id ? false : true; //Trigger the finder before save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.category', $row, $isNew)); $row->description = JRequest::getVar('description', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->description = $filter->clean($row->description); } if (!$row->id) { $row->ordering = $row->getNextOrder('parent = ' . $row->parent . ' AND trash=0'); } if (!$row->check()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=category&cid=' . $row->id); } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=categories'); } if (!$params->get('disableCompactOrdering')) { $row->reorder('parent = ' . $row->parent . ' AND trash=0'); } if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } $files = JRequest::get('files'); $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'categories' . DS; $existingImage = JRequest::getVar('existingImage'); if (($files['image']['error'] === 0 || $existingImage) && !JRequest::getBool('del_image')) { if ($files['image']['error'] === 0) { $image = $files['image']; } else { $image = JPATH_SITE . DS . JPath::clean($existingImage); } $handle = new Upload($image); if ($handle->uploaded) { $handle->file_auto_rename = false; $handle->jpeg_quality = $params->get('imagesQuality', '85'); $handle->file_overwrite = true; $handle->file_new_name_body = $row->id; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = $params->get('catImageWidth', '100'); $handle->Process($savepath); if ($files['image']['error'] === 0) { $handle->Clean(); } } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=categories'); } $row->image = $handle->file_dst_name; } if (JRequest::getBool('del_image')) { $currentRow = JTable::getInstance('K2Category', 'Table'); $currentRow->load($row->id); if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'categories' . DS . $currentRow->image)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'categories' . DS . $currentRow->image); } $row->image = ''; } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=categories'); } //Trigger the finder after save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.category', $row, $isNew)); $cache = JFactory::getCache('com_k2'); $cache->clean(); switch (JRequest::getCmd('task')) { case 'apply': $msg = JText::_('K2_CHANGES_TO_CATEGORY_SAVED'); $link = 'index.php?option=com_k2&view=category&cid=' . $row->id; break; case 'saveAndNew': $msg = JText::_('K2_CATEGORY_SAVED'); $link = 'index.php?option=com_k2&view=category'; break; case 'save': default: $msg = JText::_('K2_CATEGORY_SAVED'); $link = 'index.php?option=com_k2&view=categories'; break; } $mainframe->enqueueMessage($msg); $mainframe->redirect($link); }
$product->price_in = $_POST["price_in"]; $product->price_out = $_POST["price_out"]; $product->unit = $_POST["unit"]; $product->description = $_POST["description"]; $product->presentation = $_POST["presentation"]; $product->inventary_min = $_POST["inventary_min"]; $category_id = "NULL"; if ($_POST["category_id"] != "") { $category_id = $_POST["category_id"]; } $is_active = 0; if (isset($_POST["is_active"])) { $is_active = 1; } $product->is_active = $is_active; $product->category_id = $category_id; $product->user_id = Session::getUID(); $product->update(); if (isset($_FILES["image"])) { $image = new Upload($_FILES["image"]); if ($image->uploaded) { $image->Process("storage/products/"); if ($image->processed) { $product->image = $image->file_dst_name; $product->update_image(); } } } setcookie("prdupd", "true"); print "<script>window.location='index.php?view=editproduct&id={$_POST['product_id']}';</script>"; }
} if (picbigname) { @(list($piNameBig, $extbig) = @split("[.]", $final_image_big)); $final_image_big = $piNameBig . '.' . str_replace($findArray, $replaceArray, $extbig); } $dir_dest = "../products"; // we instanciate the class for each element of $file $handle = new Upload($_FILES['txtImage_1']); // then we check if the file has been uploaded properly // in its *temporary* location in the server (often, it is /tmp) if ($handle->uploaded) { $handle->image_resize = true; $handle->image_x = 191; $handle->image_y = 183; $handle->file_new_name_body = $piName . '_thumb'; $handle->Process($dir_dest); $handle->file_new_name_body = $piName; $handle->Process($dir_dest); $handle->image_resize = true; $handle->image_x = 283; $handle->image_y = 269; $handle->file_new_name_body = $piNameBig . '_thumb'; $handle->Process($dir_dest); $handle->file_new_name_body = $piNameBig; $handle->Process($dir_dest); } $sql_update = "UPDATE " . $tableprefix . "products SET \n\t\t\t\t\t\t\t product_image_small='" . $final_image_small . "' ,product_image_big ='" . $final_image_big . "'\n\t\t\t\t\t\t\t WHERE product_id =" . $_POST['product'] . " "; $rs_query = mysql_query($sql_update) or die(mysql_error()); } } header('Location:list_productview_images_artist.php?msg=Images Added Successfully !!');
function save() { $mainframe =& JFactory::getApplication(); jimport('joomla.filesystem.file'); require_once JPATH_COMPONENT . DS . 'lib' . DS . 'class.upload.php'; $row =& JTable::getInstance('K2User', 'Table'); $params =& JComponentHelper::getParams('com_k2'); if (!$row->bind(JRequest::get('post'))) { $mainframe->redirect('index.php?option=com_k2&view=users', $row->getError(), 'error'); } $row->description = JRequest::getVar('description', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->description = $filter->clean($row->description); } $jUser =& JFactory::getUser($row->userID); $row->userName = $jUser->name; if (!$row->store()) { $mainframe->redirect('index.php?option=com_k2&view=users', $row->getError(), 'error'); } //Image if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } $file = JRequest::get('files'); $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS; if ($file['image']['error'] == 0 && !JRequest::getBool('del_image')) { $handle = new Upload($file['image']); if ($handle->uploaded) { $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $row->id; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = $params->get('userImageWidth', '100'); $handle->Process($savepath); $handle->Clean(); } else { $mainframe->redirect('index.php?option=com_k2&view=users', $handle->error, 'error'); } $row->image = $handle->file_dst_name; } if (JRequest::getBool('del_image')) { $current =& JTable::getInstance('K2User', 'Table'); $current->load($row->id); if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS . $current->image)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS . $current->image); } $row->image = ''; } if (!$row->check()) { $mainframe->redirect('index.php?option=com_k2&view=user&cid=' . $row->id, $row->getError(), 'error'); } if (!$row->store()) { $mainframe->redirect('index.php?option=com_k2&view=users', $row->getError(), 'error'); } $cache =& JFactory::getCache('com_k2'); $cache->clean(); switch (JRequest::getCmd('task')) { case 'apply': $msg = JText::_('K2_CHANGES_TO_USER_SAVED'); $link = 'index.php?option=com_k2&view=user&cid=' . $row->userID; break; case 'save': default: $msg = JText::_('K2_USER_SAVED'); $link = 'index.php?option=com_k2&view=users'; break; } $mainframe->redirect($link, $msg); }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; global $hgconf; $task = JRequest::getVar('task'); //Sanitize $post = JRequest::get('post'); $post['service'] = JRequest::getVar('service', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['intro'] = JRequest::getVar('intro', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['location'] = JRequest::getVar('location', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['general'] = JRequest::getVar('general', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['roomgeneral'] = JRequest::getVar('roomgeneral', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['promotion'] = JRequest::getVar('promotion', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['resto'] = JRequest::getVar('resto', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['prices'] = JRequest::getVar('prices', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['otherinfo'] = JRequest::getVar('otherinfo', '', 'POST', 'string', JREQUEST_ALLOWRAW); $delete_mainimage = JRequest::getCmd('delete_mainimage', false, 'post'); $delete_logoimage = JRequest::getCmd('delete_logoimage', false, 'post'); $delete_serviceimage = JRequest::getCmd('delete_serviceimage', false, 'post'); $delete_roomimage = JRequest::getCmd('delete_roomimage', false, 'post'); $roomimage_size = $post['roomimage_size']; $directory = 'hotel_' . $post['id']; if (!$hgconf->medium_size) { $hgconf->medium_size = 240; } if (!$hgconf->thumb_size) { $hgconf->thumb_size = 64; } if (!$roomimage_size) { $roomimage_size = 240; } $model = $this->getModel('hotelitem'); if ($delete_mainimage || $delete_logoimage || $delete_serviceimage || $delete_roomimage) { $data = $model->getFiles($post['id']); if ($delete_mainimage) { $post['mainimage'] = null; $post['imagewidth'] = ''; $post['imageheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; $crop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'crop' . DS; $smallcrop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'smallcrop' . DS; if (JFile::exists($dir . $data->mainimage)) { JFile::delete($dir . $data->mainimage); } if (JFile::exists($resize_dir . $data->mainimage)) { JFile::delete($resize_dir . $data->mainimage); } if (JFile::exists($thumb_dir . $data->mainimage)) { JFile::delete($thumb_dir . $data->mainimage); } if (JFile::exists($crop_dir . $data->mainimage)) { JFile::delete($crop_dir . $data->mainimage); } if (JFile::exists($smallcrop_dir . $data->mainimage)) { JFile::delete($smallcrop_dir . $data->mainimage); } } if ($delete_serviceimage) { $post['serviceimage'] = null; $post['servicewidth'] = ''; $post['serviceheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; $crop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'crop' . DS; $smallcrop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'smallcrop' . DS; if (JFile::exists($dir . $data->serviceimage)) { JFile::delete($dir . $data->serviceimage); } if (JFile::exists($resize_dir . $data->serviceimage)) { JFile::delete($resize_dir . $data->serviceimage); } if (JFile::exists($thumb_dir . $data->serviceimage)) { JFile::delete($thumb_dir . $data->serviceimage); } } if ($delete_roomimage) { $post['roomimage'] = null; $post['roomwidth'] = ''; $post['roomheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; $crop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'crop' . DS; $smallcrop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'smallcrop' . DS; if (JFile::exists($dir . $data->roomimage)) { JFile::delete($dir . $data->roomimage); } if (JFile::exists($resize_dir . $data->roomimage)) { JFile::delete($resize_dir . $data->roomimage); } if (JFile::exists($thumb_dir . $data->roomimage)) { JFile::delete($thumb_dir . $data->roomimage); } } if ($delete_logoimage) { $post['logoimage'] = null; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS; if (JFile::exists($dir . $data->logoimage)) { JFile::delete($dir . $data->logoimage); } } } $data = $model->getFiles($post['id']); if (isset($_FILES['file_upload'])) { $typeimg = $_FILES['file_upload']['type']; if (!empty($typeimg)) { if ($typeimg == 'image/jpeg') { $ext = '.jpg'; } else { $ext = '.' . substr($typeimg, strlen($typeimg) - 3); } $filename = 'logo_' . $post['id'] . $ext; $post['logoimage'] = $filename; } $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->image_resize = true; $handle->image_ratio_x = true; $handle->image_y = 50; $handle->file_new_name_body = 'logo_' . $post['id']; $handle->Process($dir); $handle->Clean(); } } if (isset($_FILES['upload_file'])) { $imgtype = $_FILES['upload_file']['type']; if (!empty($imgtype)) { if ($imgtype == 'image/jpeg') { $ext = '.jpg'; } else { $ext = '.' . substr($imgtype, strlen($imgtype) - 3); } $mainfilename = 'main_' . $post['id'] . $ext; $post['mainimage'] = $mainfilename; } $handle = new Upload($_FILES['upload_file']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($dir); // resized image $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $hgconf->medium_size; } else { $handle->image_ratio_x = true; $handle->image_y = $hgconf->medium_size; } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($hgconf->thumb_size) { $handle->image_x = $hgconf->thumb_size; } else { $handle->image_x = 84; } } else { $handle->image_ratio_x = true; if ($hgconf->thumb_size) { $handle->image_y = $hgconf->thumb_size; } else { $handle->image_y = 84; } } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $handle->Process($thumb_dir); // crop image $crop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'crop' . DS; if (!file_exists($crop_dir)) { mkdir($crop_dir, 0777); } $handle->image_resize = true; $handle->image_ratio_crop = true; if ($hgconf->crop_size) { $handle->image_y = $hgconf->crop_size; $handle->image_x = $hgconf->crop_size; } else { $handle->image_y = 170; $handle->image_x = 170; } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $handle->Process($crop_dir); // small crop image $smallcrop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'smallcrop' . DS; if (!file_exists($smallcrop_dir)) { mkdir($smallcrop_dir, 0777); } $handle->image_resize = true; $handle->image_ratio_crop = true; $handle->image_y = 20; $handle->image_x = 20; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $handle->Process($smallcrop_dir); $handle->Clean(); } } if (isset($_FILES['upload_service'])) { $handle = new Upload($_FILES['upload_service']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($dir); $post['serviceimage'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $hgconf->medium_size; } else { $handle->image_ratio_x = true; $handle->image_y = $hgconf->medium_size; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['servicewidth'] = $imagewidth; $post['serviceheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($hgconf->thumb_size) { $handle->image_x = $hgconf->thumb_size; } else { $handle->image_x = 76; } } else { $handle->image_ratio_x = true; if ($hgconf->thumb_size) { $handle->image_y = $hgconf->thumb_size; } else { $handle->image_y = 76; } } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } if (isset($_FILES['upload_room'])) { $handle = new Upload($_FILES['upload_room']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($dir); $post['roomimage'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $roomimage_size; } else { $handle->image_ratio_x = true; $handle->image_y = $roomimage_size; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['roomwidth'] = $imagewidth; $post['roomheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($hgconf->thumb_size) { $handle->image_x = $hgconf->thumb_size; } else { $handle->image_x = 76; } } else { $handle->image_ratio_x = true; if ($hgconf->thumb_size) { $handle->image_y = $hgconf->thumb_size; } else { $handle->image_y = 76; } } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } //Update en las diferentes tablas en las cuales esta el user_id $db =& JFactory::getDBO(); $query = 'UPDATE #__hg_galleryitems SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); $query = 'UPDATE #__hg_roomitems SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); $query = 'UPDATE #__hg_restaurants SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); $query = 'UPDATE #__hg_spas SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); $query = 'UPDATE #__hg_promotions SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=hotelitem&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=hotelitem'; break; default: $link = 'index.php?option=com_hotelguide&view=hotelitems'; break; } $msg = JText::_('HG_ACCOMMODATION_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_ACCOMMODATON'); JError::raiseError(500, $model->getError()); $link = 'index.php?option=com_hotelguide&view=hotelitem'; } $model->checkin(); $this->setRedirect($link, $msg); }
function UploadArchivo() { if ($_FILES['imagearticulo']['name']) { $this->targetPathumbail = "media/proyectos/"; setlocale(LC_CTYPE, 'es'); $this->imageName = strtolower(basename($_FILES['imagearticulo']['name'])); $imageNamensinext = explode(".", $this->imageName); $name = strtolower(uniqid('file')); $this->imageName = strtolower($name . '.' . $imageNamensinext[1]); $imageNameupload = new Upload($_FILES['imagearticulo']); $imageNameupload->file_new_name_body = $name; $this->adjunto = $this->targetPathumbail . $name . '.' . $imageNamensinext[1]; if ($imageNameupload->uploaded) { $imageNameupload->Process($this->targetPathumbail); if ($imageNameupload->processed) { $this->escribeResultado(1, $this->imageName); return TRUE; } } } $this->escribeResultado(0, ""); return TRUE; }
'tipo' => $tipo, ); $db->update('productos',$campos,'id='.$id_publicacion); // Imágenes relacionadas del producto $i = 0; foreach ($_FILES as $imagenesT){ $i++; if(is_array($_FILES['imagen'.$i]) && $_FILES['imagen'.$i]['name'] != ''){ $oImgReg = new Upload($_FILES['imagen'.$i]); if ($oImgReg->uploaded) { $oImgReg->Process('productos/temp/'); $oImgReg->image_resize = true; $oImgReg->image_ratio_fill = true; $oImgReg->image_x = 1280; $oImgReg->image_y = 960; $oImgReg->allowed = array('image/*'); if ($oImgReg->processed) $imagen_original = $oImgReg->file_dst_name; $oImgReg->image_resize = true; $oImgReg->image_ratio_fill = true; $oImgReg->image_x = 1280; $oImgReg->image_y = 960; $oImgReg->allowed = array('image/*'); $oImgReg->Process('productos/');
$files[$i] = array(); } $files[$i][$k] = $v; } } // now we can loop through $files, and feed each element to the class foreach ($files as $file) { // we instanciate the class for each element of $file $handle = new Upload($file); // then we check if the file has been uploaded properly // in its *temporary* location in the server (often, it is /tmp) if ($handle->uploaded) { // now, we start the upload 'process'. That is, to copy the uploaded file // from its temporary location to the wanted location // It could be something like $handle->Process('/home/www/my_uploads/'); $handle->Process("./test/"); // we check if everything went OK if ($handle->processed) { // everything was fine ! echo '<fieldset>'; echo ' <legend>file uploaded with success</legend>'; echo ' <p>' . round(filesize($handle->file_dst_pathname) / 256) / 4 . 'KB</p>'; echo ' link to the file just uploaded: <a href="test/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>'; echo '</fieldset>'; } else { // one error occured echo '<fieldset>'; echo ' <legend>file not uploaded to the wanted location</legend>'; echo ' Error: ' . $handle->error . ''; echo '</fieldset>'; }
$punto = $_POST['point']; if($direccion == '') $punto = ''; // Verificar que usuario del cliente no exista. $i = 0; foreach ($_FILES as $imagenesT){ $i++; if(is_array($_FILES['imagen'.$i]) && $_FILES['imagen'.$i]['name'] != ''){ $oImgReg = new Upload($_FILES['imagen'.$i]); if ($oImgReg->uploaded) { $oImgReg->allowed = array('image/*'); $oImgReg->Process('imagenes/concesionario/temp/'); if ($oImgReg->processed) $imagen = $oImgReg->file_dst_name; $oImgReg->image_resize = true; $oImgReg->image_ratio_fill = true; $oImgReg->image_x = 310; $oImgReg->image_y = 212; $oImgReg->allowed = array('image/*'); $oImgReg->Process('imagenes/concesionario/'); if ($oImgReg->processed) $imagen_thumbs = $oImgReg->file_dst_name; $oImgReg->Clean(); } }
function edit_pic() { if (is_null($this->Auth->getUserId())) { Controller::render('/deny'); } if (!empty($this->data)) { // var_dump($this->data); App::import('Vendor', 'upload'); $typelist = split('/', $_FILES['data']['type']['User']['photo']); $allowed[0] = 'xxx'; $allowed[1] = 'gif'; $allowed[2] = 'jpg'; $allowed[3] = 'jpeg'; $allowed[4] = 'png'; $allowed_val = ''; $allowed_val = array_search($typelist[1], $allowed); if (!$allowed_val) { $this->Session->setFlash('<span class="bodycopy" style="color:red;">Profile picture must be gif, jpg or png only.</span>'); } else { if (!empty($this->data) && $this->data['User']['photo']['size'] > 0) { $file = $this->data['User']['photo']; $handle = new Upload($file); if ($handle->uploaded) { if ($handle->image_src_x >= 100) { $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 100; if ($handle->image_y >= 100) { $handle->image_resize = true; $handle->image_ratio_x = true; $handle->image_y = 100; } } $handle->Process('img/uploads'); } if (!is_null($handle->file_dst_name) && $handle->file_dst_name != '') { $user_path = $handle->file_dst_name; } $handle->clean(); $this->User->read(null, $this->Auth->getUserId()); $this->User->set('path', $user_path); $this->User->save(); } } $this->redirect(array('action' => 'view_my_profile')); exit; } }
$target = $_POST['target']; $link = $_POST['link']; $imagen = $_POST['himagen']; $imagen_temp = $_POST['himagen_temp']; $url_ami = urls_amigables($titulo, 'publicidad'); $portada = $_POST['portada'] == '' ? '0' : '1'; if ($_POST['chkborrar'] == '1') { $imagen = ''; $imagen_temp = ''; } // IMAGENES DE publicidad $i = 1; if (is_array($_FILES['imagen' . $i]) && $_FILES['imagen' . $i]['name'] != '') { $oImgReg = new Upload($_FILES['imagen' . $i]); if ($oImgReg->uploaded) { $oImgReg->Process('../publicidad/temp/'); if ($oImgReg->processed) { $imagen_temp = $oImgReg->file_dst_name; } //$oImgReg->image_resize = true; $oImgReg->image_ratio_crop = true; $oImgReg->image_x = 540; $oImgReg->image_y = 540; $oImgReg->allowed = array('image/*'); $oImgReg->Process('../publicidad/'); if ($oImgReg->processed) { $imagen = $oImgReg->file_dst_name; } $oImgReg->Clean(); } }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $post['rate_details'] = JRequest::getVar('rate_details', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['description'] = JRequest::getVar('description', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['amenities'] = JRequest::getVar('amenities', '', 'POST', 'string', JREQUEST_ALLOWRAW); $model = $this->getModel('roomitem'); $data = $model->getFile($post['id']); $directory = 'hotel_' . $post['hotel']; for ($i = 1; $i <= 6; $i++) { if ($i == 1) { $seq = ""; } else { $seq = $i; } eval("\$filename=\$data->filename" . $seq . ";"); $delete_image = JRequest::getCmd('delete_image' . $seq, false, 'post'); if ($delete_image) { $post['filename' . $seq] = null; $post['imagewidth'] = ''; $post['imageheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; //Elimina la foto de la carpeta album del hotel if (JFile::exists($dir . $filename)) { JFile::delete($dir . $filename); } //Elimina la foto de la carpeta resize del hotel if (JFile::exists($resize_dir . $filename)) { JFile::delete($resize_dir . $filename); } //Elimina la foto de la carpeta thumb del hotel if (JFile::exists($thumb_dir . $filename)) { JFile::delete($thumb_dir . $filename); } } else { $post['filename' . $seq] = $filename; } if (isset($_FILES['file_upload' . $seq])) { $handle = new Upload($_FILES['file_upload' . $seq]); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } if (JFile::exists($dir . $filename)) { JFile::delete($dir . $filename); } if (JFile::exists($resize_dir . $filename)) { JFile::delete($resize_dir . $filename); } if (JFile::exists($thumb_dir . $filename)) { JFile::delete($thumb_dir . $filename); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['filename' . $seq] = $handle->file_dst_name; // resized image $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 240; //$imageWidth; } else { $handle->image_ratio_x = true; $handle->image_y = 240; //$imageHeight; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 64; //$imageWidth; } else { $handle->image_ratio_x = true; $handle->image_y = 64; //$imageHeight; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=roomitem&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=roomitem'; break; default: $link = 'index.php?option=com_hotelguide&view=roomitems'; break; } $msg = JText::_('HG_ROOM_ITEM_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_ITEM'); $link = 'index.php?option=com_hotelguide&view=roomitem'; } $model->checkin(); $this->setRedirect($link, $msg); }
function makeThumb($file_url, $width, $height) { $handle = new Upload($file_url); list($width_orig, $height_orig) = @getimagesize($file_url); if (!isset($width_orig) || $width_orig == NULL) { return false; } $ratio_orig = $width_orig / $height_orig; if ($width == '') { $width = $height * $ratio_orig; } elseif ($height == '') { $height = $width / $ratio_orig; } if ($width / $height > $ratio_orig) { $width = $height * $ratio_orig; } else { $height = $width / $ratio_orig; } $check['width'] = (int) $width; $check['height'] = (int) $height; if ($check['width'] == 0 && $check['height'] == 0) { return NULL; } $width = number_format($width, 0); $height = number_format($height, 0); $pieces = explode(DS, $file_url); $filename = explode('.', $pieces[count($pieces) - 1]); $pieces[count($pieces) - 1] = ''; $pieces = implode(DS, $pieces); $dir_dest = $pieces; if ($handle->uploaded) { $handle->image_resize = true; $handle->image_x = $width; $handle->image_y = $height; $handle->file_new_name_body = $filename[0] . '_w' . $width . '_h' . $height; $handle->file_overwrite = true; $handle->jpeg_quality = 100; $handle->Process($dir_dest); if ($handle->processed) { return $handle->file_dst_name; } else { return false; } } else { return false; } }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); global $hgconf; jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $post['description'] = JRequest::getVar('description', '', 'POST', 'string', JREQUEST_ALLOWRAW); $delete_image = JRequest::getCmd('delete_image', false, 'post'); $model = $this->getModel('promotion'); $data = $model->getFile($post['id']); $directory = 'hotel_' . $post['hotel']; if (!$hgconf->medium_size) { $hgconf->medium_size = 240; } if (!$hgconf->thumb_size) { $hgconf->thumb_size = 64; } if ($delete_image) { $post['filename'] = null; $post['imagewidth'] = ''; $post['imageheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (JFile::exists($dir . $data->filename)) { JFile::delete($dir . $data->filename); } if (JFile::exists($resize_dir . $data->filename)) { JFile::delete($resize_dir . $data->filename); } if (JFile::exists($thumb_dir . $data->filename)) { JFile::delete($thumb_dir . $data->filename); } } if (isset($_FILES['file_upload'])) { $filename = $_FILES['file_upload']['name']; $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['filename'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $hgconf->medium_size; } else { $handle->image_ratio_x = true; $handle->image_y = $hgconf->medium_size; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $hgconf->thumb_size; } else { $handle->image_ratio_x = true; $handle->image_y = $hgconf->thumb_size; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=promotion&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=promotion'; break; default: $link = 'index.php?option=com_hotelguide&view=promotions'; break; } $msg = JText::_('HG_PROMOTION_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_ITEM'); $link = 'index.php?option=com_hotelguide&view=promotion'; } $model->checkin(); $this->setRedirect($link, $msg); }
<?php /** * @author evilnapsis * @brief Descripcion **/ if (Session::exists("user_id") && !empty($_POST)) { $image = null; $image_id = 0; $handle = new Upload($_FILES['image']); if ($handle->uploaded) { $url = "storage/users/{$_SESSION['user_id']}/images/"; $handle->Process($url); // $handle->file_dst_name; $image = new ImageData(); $image->src = $handle->file_dst_name; $image->level_id = $_POST["level_id"]; $image->user_id = $_SESSION["user_id"]; $image_id = $image->add(); } $post_id = 0; if ($_POST["content"] != "") { $post = new PostData(); $post->content = $_POST["content"]; $post->level_id = $_POST["level_id"]; $post->author_ref_id = $_SESSION["user_id"]; $post->receptor_ref_id = $_SESSION["user_id"]; $post_id = $post->add(); if ($handle->uploaded) { $pi = new PostImageData(); $pi->post_id = $post_id[1];
/** * Logic to save a brand * * @access public * @return void * @since 1.5 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $post['description'] = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $model = $this->getModel('city'); if (isset($_FILES['file_upload'])) { $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_CITY_ALBUM_URL; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['image'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_CITY_RESIZE_URL; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($post['image_size']) { $handle->image_x = $post['image_size']; } else { $handle->image_x = 240; } } else { $handle->image_ratio_x = true; if ($post['image_size']) { $handle->image_y = $post['image_size']; } else { $handle->image_y = 240; } } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_CITY_THUMB_URL; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 74; } else { $handle->image_ratio_x = true; $handle->image_y = 74; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); // thumbnail image $crop_dir = HOTELGUIDE_IMAGES_CITY_CROP_URL; if (!file_exists($crop_dir)) { mkdir($crop_dir, 0777); } $handle->image_resize = true; $handle->image_ratio_crop = true; $handle->image_y = 90; $handle->image_x = 90; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($crop_dir); // thumbnail image $scrop_dir = HOTELGUIDE_IMAGES_CITY_SCROP_URL; if (!file_exists($scrop_dir)) { mkdir($scrop_dir, 0777); } $handle->image_resize = true; $handle->image_ratio_crop = true; $handle->image_y = 20; $handle->image_x = 20; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($scrop_dir); $handle->Clean(); } } if (isset($_FILES['title_upload'])) { $handle = new Upload($_FILES['title_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_CITY_ALBUM_URL; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['titleimage'] = $handle->file_dst_name; $post['titleimagewidth'] = $width; $post['titleimageheight'] = $height; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_CITY_THUMB_URL; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 74; } else { $handle->image_ratio_x = true; $handle->image_y = 74; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=city&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=city'; break; default: $link = 'index.php?option=com_hotelguide&view=cities'; break; } $msg = JText::_('HG_CITY_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_CITY'); //JError::raiseWarning( 500, $model->getError() ); $link = 'index.php?option=com_hotelguide&view=city'; } $model->checkin(); $this->setRedirect($link, $msg); }
function save($front = false) { $mainframe = JFactory::getApplication(); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.archive'); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $db = JFactory::getDBO(); $user = JFactory::getUser(); $row = JTable::getInstance('K2Item', 'Table'); $params = JComponentHelper::getParams('com_k2'); $nullDate = $db->getNullDate(); if (!$row->bind(JRequest::get('post'))) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } if ($front && $row->id == NULL) { JLoader::register('K2HelperPermissions', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'permissions.php'); if (!K2HelperPermissions::canAddItem($row->catid)) { $mainframe->enqueueMessage(JText::_('K2_YOU_ARE_NOT_ALLOWED_TO_POST_TO_THIS_CATEGORY_SAVE_FAILED'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=item&task=add&tmpl=component'); } } $isNew = $row->id ? false : true; // If we are in front-end and the item is not new we need to get it's current published state. if (!$isNew && $front) { $id = JRequest::getInt('id'); $currentRow = JTable::getInstance('K2Item', 'Table'); $currentRow->load($id); $isAlreadyPublished = $currentRow->published; $currentFeaturedState = $currentRow->featured; } if ($params->get('mergeEditors')) { $text = JRequest::getVar('text', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $text = $filter->clean($text); } $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i'; $tagPos = preg_match($pattern, $text); if ($tagPos == 0) { $row->introtext = $text; $row->fulltext = ''; } else { list($row->introtext, $row->fulltext) = preg_split($pattern, $text, 2); } } else { $row->introtext = JRequest::getVar('introtext', '', 'post', 'string', 2); $row->fulltext = JRequest::getVar('fulltext', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->introtext = $filter->clean($row->introtext); $row->fulltext = $filter->clean($row->fulltext); } } if ($row->id) { $datenow = JFactory::getDate(); $row->modified = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $row->modified_by = $user->get('id'); } else { $row->ordering = $row->getNextOrder("catid = {$row->catid} AND trash = 0"); if ($row->featured) { $row->featured_ordering = $row->getNextOrder("featured = 1 AND trash = 0", 'featured_ordering'); } } $row->created_by = $row->created_by ? $row->created_by : $user->get('id'); if ($front) { $K2Permissions = K2Permissions::getInstance(); if (!$K2Permissions->permissions->get('editAll')) { $row->created_by = $user->get('id'); } } if ($row->created && strlen(trim($row->created)) <= 10) { $row->created .= ' 00:00:00'; } $config = JFactory::getConfig(); $tzoffset = K2_JVERSION == '30' ? $config->get('offset') : $config->getValue('config.offset'); $date = JFactory::getDate($row->created, $tzoffset); $row->created = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); if (strlen(trim($row->publish_up)) <= 10) { $row->publish_up .= ' 00:00:00'; } $date = JFactory::getDate($row->publish_up, $tzoffset); $row->publish_up = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); if (trim($row->publish_down) == JText::_('K2_NEVER') || trim($row->publish_down) == '') { $row->publish_down = $nullDate; } else { if (strlen(trim($row->publish_down)) <= 10) { $row->publish_down .= ' 00:00:00'; } $date = JFactory::getDate($row->publish_down, $tzoffset); $row->publish_down = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); } $metadata = JRequest::getVar('meta', null, 'post', 'array'); if (is_array($metadata)) { $txt = array(); foreach ($metadata as $k => $v) { if ($k == 'description') { $row->metadesc = $v; } elseif ($k == 'keywords') { $row->metakey = $v; } else { $txt[] = "{$k}={$v}"; } } $row->metadata = implode("\n", $txt); } if (!$row->check()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=item&cid=' . $row->id); } $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $result = $dispatcher->trigger('onBeforeK2Save', array(&$row, $isNew)); if (in_array(false, $result, true)) { JError::raiseError(500, $row->getError()); return false; } //Trigger the finder before save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.item', $row, $isNew)); // Try to save the video if there is no need to wait for item ID if (!JRequest::getBool('del_video')) { if (!isset($files['video'])) { if (JRequest::getVar('remoteVideo')) { $fileurl = JRequest::getVar('remoteVideo'); $filetype = JFile::getExt($fileurl); $row->video = '{' . $filetype . 'remote}' . $fileurl . '{/' . $filetype . 'remote}'; } if (JRequest::getVar('videoID')) { $provider = JRequest::getWord('videoProvider'); $videoID = JRequest::getVar('videoID'); $row->video = '{' . $provider . '}' . $videoID . '{/' . $provider . '}'; } if (JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW)) { $row->video = JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW); } } } // JoomFish! Front-end editing compatibility if ($mainframe->isSite() && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php')) { if (version_compare(phpversion(), '5.0') < 0) { $tmpRow = $row; } else { $tmpRow = clone $row; } } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } // JoomFish! Front-end editing compatibility if ($mainframe->isSite() && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php')) { $itemID = $row->id; $row = $tmpRow; $row->id = $itemID; } if (!$params->get('disableCompactOrdering')) { $row->reorder("catid = {$row->catid} AND trash = 0"); } if ($row->featured && !$params->get('disableCompactOrdering')) { $row->reorder("featured = 1 AND trash = 0", 'featured_ordering'); } $files = JRequest::get('files'); //Image if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } $existingImage = JRequest::getVar('existingImage'); if (($files['image']['error'] === 0 || $existingImage) && !JRequest::getBool('del_image')) { if ($files['image']['error'] === 0) { $image = $files['image']; } else { $image = JPATH_SITE . DS . JPath::clean($existingImage); } $handle = new Upload($image); $handle->allowed = array('image/*'); if ($handle->uploaded) { //Image params $category = JTable::getInstance('K2Category', 'Table'); $category->load($row->catid); $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params); if ($cparams->get('inheritFrom')) { $masterCategoryID = $cparams->get('inheritFrom'); $query = "SELECT * FROM #__k2_categories WHERE id=" . (int) $masterCategoryID; $db->setQuery($query, 0, 1); $masterCategory = $db->loadObject(); $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params); } $params->merge($cparams); //Original image $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src'; $handle->image_convert = 'jpg'; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = md5("Image" . $row->id); $handle->Process($savepath); $filename = $handle->file_dst_name_body; $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache'; //XLarge image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_XL'; if (JRequest::getInt('itemImageXL')) { $imageWidth = JRequest::getInt('itemImageXL'); } else { $imageWidth = $params->get('itemImageXL', '800'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Large image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_L'; if (JRequest::getInt('itemImageL')) { $imageWidth = JRequest::getInt('itemImageL'); } else { $imageWidth = $params->get('itemImageL', '600'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Medium image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_M'; if (JRequest::getInt('itemImageM')) { $imageWidth = JRequest::getInt('itemImageM'); } else { $imageWidth = $params->get('itemImageM', '400'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Small image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_S'; if (JRequest::getInt('itemImageS')) { $imageWidth = JRequest::getInt('itemImageS'); } else { $imageWidth = $params->get('itemImageS', '200'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //XSmall image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_XS'; if (JRequest::getInt('itemImageXS')) { $imageWidth = JRequest::getInt('itemImageXS'); } else { $imageWidth = $params->get('itemImageXS', '100'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Generic image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_Generic'; $imageWidth = $params->get('itemImageGeneric', '300'); $handle->image_x = $imageWidth; $handle->Process($savepath); if ($files['image']['error'] === 0) { $handle->Clean(); } } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } if (JRequest::getBool('del_image')) { $current = JTable::getInstance('K2Item', 'Table'); $current->load($row->id); $filename = md5("Image" . $current->id); if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg'); } $row->image_caption = ''; $row->image_credits = ''; } //Attachments $attachments = JRequest::getVar('attachment_file', NULL, 'FILES', 'array'); $attachments_names = JRequest::getVar('attachment_name', '', 'POST', 'array'); $attachments_titles = JRequest::getVar('attachment_title', '', 'POST', 'array'); $attachments_title_attributes = JRequest::getVar('attachment_title_attribute', '', 'POST', 'array'); $attachments_existing_files = JRequest::getVar('attachment_existing_file', '', 'POST', 'array'); $attachmentFiles = array(); if (count($attachments)) { foreach ($attachments as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $attachmentFiles)) { $attachmentFiles[$i] = array(); } $attachmentFiles[$i][$k] = $v; } } $path = $params->get('attachmentsFolder', NULL); if (is_null($path)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments'; } else { $savepath = $path; } $counter = 0; foreach ($attachmentFiles as $key => $file) { if ($file["tmp_name"] || $attachments_existing_files[$key]) { if ($attachments_existing_files[$key]) { $src = JPATH_SITE . DS . JPath::clean($attachments_existing_files[$key]); $copyName = basename($src); $dest = $savepath . DS . $copyName; if (JFile::exists($dest)) { $existingFileName = JFile::getName($dest); $ext = JFile::getExt($existingFileName); $basename = JFile::stripExt($existingFileName); $newFilename = $basename . '_' . time() . '.' . $ext; $copyName = $newFilename; $dest = $savepath . DS . $newFilename; } JFile::copy($src, $dest); $attachment = JTable::getInstance('K2Attachment', 'Table'); $attachment->itemID = $row->id; $attachment->filename = $copyName; $attachment->title = empty($attachments_titles[$counter]) ? $filename : $attachments_titles[$counter]; $attachment->titleAttribute = empty($attachments_title_attributes[$counter]) ? $filename : $attachments_title_attributes[$counter]; $attachment->store(); } else { $handle = new Upload($file); if ($handle->uploaded) { $handle->file_auto_rename = true; $handle->allowed[] = 'application/x-zip'; $handle->allowed[] = 'application/download'; $handle->Process($savepath); $filename = $handle->file_dst_name; $handle->Clean(); $attachment = JTable::getInstance('K2Attachment', 'Table'); $attachment->itemID = $row->id; $attachment->filename = $filename; $attachment->title = empty($attachments_titles[$counter]) ? $filename : $attachments_titles[$counter]; $attachment->titleAttribute = empty($attachments_title_attributes[$counter]) ? $filename : $attachments_title_attributes[$counter]; $attachment->store(); } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } } $counter++; } } //Gallery $flickrGallery = JRequest::getVar('flickrGallery'); if ($flickrGallery) { $row->gallery = '{gallery}' . $flickrGallery . '{/gallery}'; } if (isset($files['gallery']) && $files['gallery']['error'] == 0 && !JRequest::getBool('del_gallery')) { $handle = new Upload($files['gallery']); $handle->file_auto_rename = true; $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries'; $handle->allowed = array("application/download", "application/rar", "application/x-rar-compressed", "application/arj", "application/gnutar", "application/x-bzip", "application/x-bzip2", "application/x-compressed", "application/x-gzip", "application/x-zip-compressed", "application/zip", "multipart/x-zip", "multipart/x-gzip", "application/x-unknown", "application/x-zip"); if ($handle->uploaded) { $handle->Process($savepath); $handle->Clean(); if (JFolder::exists($savepath . DS . $row->id)) { JFolder::delete($savepath . DS . $row->id); } if (!JArchive::extract($savepath . DS . $handle->file_dst_name, $savepath . DS . $row->id)) { $mainframe->enqueueMessage(JText::_('K2_GALLERY_UPLOAD_ERROR_CANNOT_EXTRACT_ARCHIVE'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } else { $row->gallery = '{gallery}' . $row->id . '{/gallery}'; } JFile::delete($savepath . DS . $handle->file_dst_name); $handle->Clean(); } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } if (JRequest::getBool('del_gallery')) { $current = JTable::getInstance('K2Item', 'Table'); $current->load($row->id); if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id)) { JFolder::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id); } $row->gallery = ''; } //Video if (!JRequest::getBool('del_video')) { if (isset($files['video']) && $files['video']['error'] == 0) { $videoExtensions = array("flv", "mp4", "ogv", "webm", "f4v", "m4v", "3gp", "3g2", "mov", "mpeg", "mpg", "avi", "wmv", "divx"); $audioExtensions = array("mp3", "aac", "m4a", "ogg", "wma"); $validExtensions = array_merge($videoExtensions, $audioExtensions); $filetype = JFile::getExt($files['video']['name']); if (!in_array($filetype, $validExtensions)) { $mainframe->enqueueMessage(JText::_('K2_INVALID_VIDEO_FILE'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } if (in_array($filetype, $videoExtensions)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos'; } else { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio'; } $filename = JFile::stripExt($files['video']['name']); JFile::upload($files['video']['tmp_name'], $savepath . DS . $row->id . '.' . $filetype); $filetype = JFile::getExt($files['video']['name']); $row->video = '{' . $filetype . '}' . $row->id . '{/' . $filetype . '}'; } } else { $current = JTable::getInstance('K2Item', 'Table'); $current->load($row->id); preg_match_all("#^{(.*?)}(.*?){#", $current->video, $matches, PREG_PATTERN_ORDER); $videotype = $matches[1][0]; $videofile = $matches[2][0]; if (in_array($videotype, $videoExtensions)) { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype); } } if (in_array($videotype, $audioExtensions)) { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype); } } $row->video = ''; $row->video_caption = ''; $row->video_credits = ''; } //Extra fields $objects = array(); $variables = JRequest::get('post', 2); foreach ($variables as $key => $value) { if ((bool) JString::stristr($key, 'K2ExtraField_')) { $object = new JObject(); $object->set('id', JString::substr($key, 13)); if (is_string($value)) { $value = trim($value); } $object->set('value', $value); unset($object->_errors); $objects[] = $object; } } $csvFiles = JRequest::get('files'); foreach ($csvFiles as $key => $file) { if ((bool) JString::stristr($key, 'K2ExtraField_')) { $object = new JObject(); $object->set('id', JString::substr($key, 13)); $csvFile = $file['tmp_name'][0]; if (!empty($csvFile) && JFile::getExt($file['name'][0]) == 'csv') { $handle = @fopen($csvFile, 'r'); $csvData = array(); while (($data = fgetcsv($handle, 1000)) !== FALSE) { $csvData[] = $data; } fclose($handle); $object->set('value', $csvData); } else { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'JSON.php'; $json = new Services_JSON(); $object->set('value', $json->decode(JRequest::getVar('K2CSV_' . $object->id))); if (JRequest::getBool('K2ResetCSV_' . $object->id)) { $object->set('value', null); } } unset($object->_errors); $objects[] = $object; } } require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'JSON.php'; $json = new Services_JSON(); $row->extra_fields = $json->encode($objects); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php'; $extraFieldModel = K2Model::getInstance('ExtraField', 'K2Model'); $row->extra_fields_search = ''; foreach ($objects as $object) { $row->extra_fields_search .= $extraFieldModel->getSearchValue($object->id, $object->value); $row->extra_fields_search .= ' '; } //Tags if ($user->gid < 24 && $params->get('lockTags')) { $params->set('taggingSystem', 0); } $db = JFactory::getDBO(); $query = "DELETE FROM #__k2_tags_xref WHERE itemID={intval({$row->id})}"; $db->setQuery($query); $db->query(); if ($params->get('taggingSystem')) { if ($user->gid < 24 && $params->get('lockTags')) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } $tags = JRequest::getVar('tags', NULL, 'POST', 'array'); if (count($tags)) { $tags = array_unique($tags); foreach ($tags as $tag) { $tag = JString::trim($tag); if ($tag) { $tagID = false; $K2Tag = JTable::getInstance('K2Tag', 'Table'); $K2Tag->name = $tag; // Tag has been filtred and does not exist if ($K2Tag->check()) { $K2Tag->published = 1; if ($K2Tag->store()) { $tagID = $K2Tag->id; } } else { if ($K2Tag->name) { $query = "SELECT id FROM #__k2_tags WHERE name=" . $db->Quote($K2Tag->name); $db->setQuery($query); $tagID = $db->loadResult(); } } if ($tagID) { $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } } } } } else { $tags = JRequest::getVar('selectedTags', NULL, 'POST', 'array'); if (count($tags)) { foreach ($tags as $tagID) { $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } } } // If we are in front-end check publishing permissions properly. if ($front) { // New items require the "Publish items" permission. if ($isNew && $row->published && !K2HelperPermissions::canPublishItem($row->catid)) { $row->published = 0; $mainframe->enqueueMessage(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'), 'notice'); } // Existing items require either the "Publish items" or the "Allow editing of already published items" permission. if (!$isNew && $row->published) { $canEditPublished = $isAlreadyPublished && K2HelperPermissions::canEditPublished($row->catid); if (!K2HelperPermissions::canPublishItem($row->catid) && !$canEditPublished) { $row->published = 0; $mainframe->enqueueMessage(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'), 'notice'); } } // If user has cannot publish the item then also cannot make it featured if (!K2HelperPermissions::canPublishItem($row->catid)) { if ($isNew) { $row->featured = 0; } else { $row->featured = $currentFeaturedState; } } } $query = "UPDATE #__k2_items SET \n video_caption = " . $db->Quote($row->video_caption) . ", \n video_credits = " . $db->Quote($row->video_credits) . ", "; if (!is_null($row->video)) { $query .= " video = " . $db->Quote($row->video) . ", "; } if (!is_null($row->gallery)) { $query .= " gallery = " . $db->Quote($row->gallery) . ", "; } $query .= " extra_fields = " . $db->Quote($row->extra_fields) . ", \n extra_fields_search = " . $db->Quote($row->extra_fields_search) . " ,\n published = " . $db->Quote($row->published) . " \n WHERE id = " . $row->id; $db->setQuery($query); if (!$db->query()) { $mainframe->enqueueMessage($db->getErrorMsg(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } $row->checkin(); $cache = JFactory::getCache('com_k2'); $cache->clean(); $dispatcher->trigger('onAfterK2Save', array(&$row, $isNew)); JPluginHelper::importPlugin('content'); if (K2_JVERSION != '15') { $dispatcher->trigger('onContentAfterSave', array('com_k2.item', &$row, $isNew)); } else { $dispatcher->trigger('onAfterContentSave', array(&$row, $isNew)); } //Trigger the finder after save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.item', $row, $isNew)); switch (JRequest::getCmd('task')) { case 'apply': $msg = JText::_('K2_CHANGES_TO_ITEM_SAVED'); $link = 'index.php?option=com_k2&view=item&cid=' . $row->id; break; case 'saveAndNew': $msg = JText::_('K2_ITEM_SAVED'); $link = 'index.php?option=com_k2&view=item'; break; case 'save': default: $msg = JText::_('K2_ITEM_SAVED'); if ($front) { $link = 'index.php?option=com_k2&view=item&task=edit&cid=' . $row->id . '&tmpl=component&Itemid=' . JRequest::getInt('Itemid'); } else { $link = 'index.php?option=com_k2&view=items'; } break; } $mainframe->enqueueMessage($msg); $mainframe->redirect($link); }
$file->file_new_name_body = $number . '-post-x900'; /*This variable comes from the sql request done just before*/ $file->image_resize = true; $file->file_overwrite = true; $file->image_ratio_crop = true; $file->image_x = 900; $file->image_y = 900; $file->image_text = $text; $file->image_text_color = "#ffffff"; $file->image_text_background = "#000000"; $file->image_text_background_opacity = 67; $file->image_text_font = 5; $file->image_text_position = "BR"; $file->image_text_padding = 15; $file->image_text_line_spacing = 10; $file->Process('./uploads/img'); if ($file->processed) { $query = 'INSERT INTO gallery_posts(source, title, ip, datetime) VALUES(:source, :title, :ip, :datetime)'; $preparedStatement = $bdd->prepare($query); $preparedStatement->bindParam(':source', $source); $preparedStatement->bindParam(':title', $text); $preparedStatement->bindParam(':ip', $ip); $preparedStatement->bindParam(':datetime', $date); $preparedStatement->execute(); $posts = $preparedStatement->fetchAll(PDO::FETCH_ASSOC); header('Location:index.php'); } else { die('Error: ' . $file->error); exit; } }
function imageFrame($filename = false, $framefile = false) { global $IMAGE, $CONFIG; if (array_key_exists('mobile', $CONFIG)) { include APP . LIBS . 'class_image_upload/class.upload.php'; } else { include LIBS . 'class_image_upload/class.upload.php'; } deleteFile($filename, 'imageFramed'); // pr($IMAGE[0]['pathfile'].$filename); $handle = new Upload($IMAGE[0]['pathfile'] . $filename); // pr($handle); if ($handle->uploaded) { $handle->image_resize = true; $handle->image_x = 180; $handle->image_y = 181; $handle->image_ratio_crop = false; $handle->jpeg_quality = 100; $handle->image_watermark = $IMAGE[0]['pathframe'] . $framefile; $handle->Process($IMAGE[0]['imageframed']); if ($handle->processed) { $filename = $handle->file_dst_name; } else { echo 'Error: ' . $handle->error . ''; } $handle->Clean(); return true; } else { echo 'Error: ' . $handle->error . ''; } return false; }