public function index() { $this->load->library('upload'); $handle = new Upload($_FILES['upload']); $filename = time() . rand(0, 999); $handle->file_new_name_body = md5($filename); if ($handle->uploaded) { $dir = date('/Y/m/d/'); $path = DIR_UPLOAD . 'images' . $dir; $handle->process($path); if ($handle->processed) { $handle->clean(); $response['status'] = true; $response['data'] = array('path' => '/upload/images' . $dir . $handle->file_dst_name, 'name' => $handle->file_src_name); $response['message'] = 'success'; } else { $response['status'] = false; $response['data'] = ''; $response['message'] = $handle->error; } } $this->response->outputJson($response); }
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; } }
/** * Checks a registration request for invalid inputs * * @access public * @return true */ function complete_upload_match_media() { if (valid_request(array(isset($_GET['match_id']), isset($_FILES['match_media']), isset($_POST['description'])))) { require CLASS_PATH . 'class.upload.php'; global $db; global $smarty; if (strlen($_POST['description']) < 2 || strlen($_POST['description']) > 20) { display_errors(751); return true; } $upload = new Upload($_FILES['match_media']); if ($upload->uploaded) { //getting the internal file name out of the current time $name = microtime(); $name = substr($name, 2, 8) . substr($name, 11); $upload->file_new_name_body = $name; $upload->allowed = array('application/zip', 'image/*'); $upload->process(MATCH_MEDIA_PATH); if ($upload->processed) { $sql = "add_match_media(" . $_GET['match_id'] . ",\n " . $_SESSION['user_id'] . ",\n '" . $_POST['description'] . "',\n '" . $upload->file_dst_name . "', \n " . filesize($upload->file_dst_pathname) . ")"; $db->run($sql); if ($db->error_result) { display_errors(750); } else { display_success("upload_match_media"); $smarty->assign('content', $smarty->fetch("succes.tpl")); } } else { display_errors(750); } $upload->clean(); } else { display_errors(750); return true; } } return true; }
/** * 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; }
<?php error_reporting(E_ALL); require_once 'classes/upload.class.php'; require_once 'global.inc.php'; $user = unserialize($_SESSION['user']); if ($_SESSION['logged_in'] == 1) { $handle = new Upload($_FILES['image_field']); if ($handle->uploaded) { $handle->process('../images/profilePics/' . $user->id); if ($handle->processed) { $fileName = 'images/profilePics/' . $user->id . '/' . $handle->file_src_name; $handle->clean(); $sql = 'UPDATE members SET photo= "' . $fileName . '" WHERE id= "' . $user->id . '"'; mysql_query($sql) or die(mysql_error()); header('location:../settings.php'); } else { echo 'It failed'; } } }
require_once 'classes/upload/class.upload.php'; $img = new Upload($imagem, 'pt_BR'); $img->file_new_name_body = substr(md5(uniqid(time())), 0, 15); $img->image_max_width = $config['larguraMax']; $img->image_max_height = $config['alturaMax']; $img->image_resize = $config['resize']; $img->image_ratio_x = true; $img->image_ratio_y = true; $img->image_x = $config['img_x']; $img->image_y = $config['img_y']; $img->image_convert = $config['convert_to']; $img->jpeg_quality = $config['jpeg_quality']; $img->image_text = $config['image_text']; $img->image_text_direction = $config['image_text']; $img->image_text_color = $config['image_text_color']; $img->image_text_percent = $config['image_text_percent']; $img->image_text_position = $config['image_text_position']; $img->image_text_alignment = $config['image_text_alignment']; $img->allowed = array('image/*'); $img->file_max_size = $config['_tamanho']; $img->process($config['diretorio']); if ($img->processed) { echo '<script>parent.TretaImgUpload.insere(\'' . $img->file_dst_name . '\')</script>;'; $img->clean(); $imgs[] = $img->file_dst_name; $_SESSION['imgs_upadas'] = $imgs; } else { exit('<script>parent.TretaImgUpload.msg("' . $img->error . '")</script>'); } } }
public function saveImage($data) { $jinput = JFactory::getApplication()->input; $uploaded_image = $jinput->files->get('jform')['image']; //error_log("uploaded_image name --> " . print_r($uploaded_image,true)); //error_log("Image name --> " . $uploaded_image['name']); //any errors the server registered on uploading $recipe_name = $data['recipe_name']; $image_name = str_replace(' ', '_', $recipe_name); $image_name = preg_replace('/[^A-Za-z0-9\\_]/', '', $image_name); $savepath = 'images' . DIRECTORY_SEPARATOR . 'archanaskitchen' . DIRECTORY_SEPARATOR . '1-Author'; $user = JFactory::getUser(); if ($user->guest) { $savepath = $savepath . DIRECTORY_SEPARATOR . 'guest'; } else { $savepath = $savepath . DIRECTORY_SEPARATOR . str_replace('@', '-', $user->username); } require_once JPATH_COMPONENT_ADMINISTRATOR . '/lib/class.upload.php'; $handle = new Upload($uploaded_image); $handle->allowed = array('image/*'); if ($handle->uploaded) { // $handle->file_new_name_body = $image_name . '_original' ; // $handle->image_resize = false; // $handle->process(JPATH_SITE . DIRECTORY_SEPARATOR . $savepath); $original_file = JPATH_SITE . DIRECTORY_SEPARATOR . $savepath . DIRECTORY_SEPARATOR . $image_name . '_original.jpg'; error_log("Copying uploaded image " . $handle->file_src_name . ' to ' . $original_file); copy($handle->file_src_pathname, $original_file); /* if ( !$handle->processed ) { error_log("Error Processing Image upload " . $handle->error); $this->setError("Error Processing Image upload " . $handle->error); return false; } */ $handle->file_overwrite = false; $handle->image_convert = 'jpg'; $handle->file_new_name_body = $image_name; $handle->file_overwrite = true; if ($handle->image_src_x >= 1600) { $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 1600; if ($handle->file_src_size > 204800) { $handle->jpeg_size = 150 * 1024; } } $handle->process(JPATH_SITE . DIRECTORY_SEPARATOR . $savepath); if (!$handle->processed) { error_log("Error Processing Image upload " . $handle->error); $this->setError("Error Processing Image upload " . $handle->error); //return false; } $handle->clean(); } else { error_log("Error Processing Image upload " . $handle->error); $this->setError("Error Processing Image upload " . $handle->error); //return false; } return $savepath . DIRECTORY_SEPARATOR . $image_name . '.jpg'; }
$document->file_overwrite = true; $document->Process('photos/'); $name = $document->file_dst_name; //on récupére l'adresse ip de l'utilisateur if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } if ($document->processed) { $query = "INSERT \r\n INTO photos (name, last_co, ip) \r\n VALUE (:name, :last_co, :ip)"; $params = array(":name" => $name, ":last_co" => $last_co, ":ip" => $ip); $preparedStatement = $connexion->prepare($query); $preparedStatement->execute($params); echo "<p class='messagebon'>Votre image a été uploadée</p>"; $document->clean(); } else { echo "<p class='message'>Une erreur est survenue</p>"; } } } else { if ($extension_fichier == "") { echo "<p class='message'>Aucun fichier sélectionné</p>"; } else { echo "<p class='message'>Mauvais format de fichier</p>"; } } unset($document); }
| GNU General Public License for more details. | | | | You should have received a copy of the GNU General Public License | | along with this program; if not, write to the | | Free Software Foundation, Inc., 59 Temple Place, Suite 330, | | Boston, MA 02111-1307 USA | | | +------------------------------------------------------------------------+ */ require_once 'includes/init.php'; // our object $uploadedImage = new Upload($_FILES['uploadImage']); if ($uploadedImage->uploaded) { // only images are allowed $uploadedImage->allowed = array('image/*'); // jpg quality $uploadedImage->jpeg_quality = 100; // process the whole thing in the PROCESS_DIR check init.php $uploadedImage->Process(PROCESS_DIR); if ($uploadedImage->processed) { // get all the uploaded file details $fileName = $uploadedImage->file_dst_name; $width = $uploadedImage->image_src_x; $height = $uploadedImage->image_src_y; // output json data echo json_encode(array('image' => $fileName, 'width' => $width, 'height' => $height)); } else { echo json_encode(array('error' => $uploadedImage->error)); } $uploadedImage->clean(); }
protected function saveImage($data) { $jinput = JFactory::getApplication()->input; $uploaded_image = $jinput->files->get('jform')['images']['image_fulltext']; $title = $data->title; $image_name = str_replace(' ', '_', $title); $image_name = preg_replace('/[^A-Za-z0-9\\_]/', '', $image_name); $savepath = 'images' . DIRECTORY_SEPARATOR . 'archanaskitchen' . DIRECTORY_SEPARATOR . '1-Author'; $user = JFactory::getUser(); if ($user->guest) { $savepath = $savepath . DIRECTORY_SEPARATOR . 'guest'; } else { $savepath = $savepath . DIRECTORY_SEPARATOR . str_replace('@', '-', $user->username); } $handle = new Upload($uploaded_image); $handle->allowed = array('image/*'); if ($handle->uploaded) { $original_file = JPATH_SITE . DIRECTORY_SEPARATOR . $savepath . DIRECTORY_SEPARATOR . $image_name . '_original.' . $handle->file_src_name_ext; error_log("Copying uploaded image " . $handle->file_src_name . ' to ' . $original_file); copy($handle->file_src_pathname, $original_file); $handle->file_overwrite = false; $handle->image_convert = 'jpg'; $handle->file_new_name_body = $image_name; $handle->file_overwrite = true; if ($handle->image_src_x >= 1600) { $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 1600; if ($handle->file_src_size > 204800) { $handle->jpeg_size = 150 * 1024; } } $handle->process(JPATH_SITE . DIRECTORY_SEPARATOR . $savepath); if (!$handle->processed) { error_log("Error Processing Image upload " . $handle->error); $this->setError("Error Processing Image upload " . $handle->error); //return false; } $handle->clean(); } else { error_log("Error Processing Image upload " . $handle->error); $this->setError("Error Processing Image upload " . $handle->error); //return false; } return $savepath . DIRECTORY_SEPARATOR . $image_name . '.jpg'; }
/** * Felhasználó képének vágása és feltöltése * Az $this->registry->params['id'] paraméter értékétől függően feltölti a kiválasztott képet * upload paraméter esetén: feltölti a kiválasztott képet * crop paraméter esetén: megvágja a kiválasztott képet és feltölti * */ public function user_img_upload() { if (isset($this->registry->params['id'])) { include LIBS . "/upload_class.php"; // Kiválasztott kép feltöltése if ($this->registry->params['id'] == 'upload') { // feltöltés helye $imagePath = Config::get('user.upload_path'); //képkezelő objektum létrehozása (a kép a szerveren a tmp könyvtárba kerül) $handle = new Upload($_FILES['img']); if ($handle->uploaded) { // kép paramétereinek módosítása $handle->file_auto_rename = true; $handle->file_safe_name = true; //$handle->file_new_name_body = 'lorem ipsum'; $handle->allowed = array('image/*'); $handle->image_resize = true; $handle->image_x = Config::get('user.width', 600); $handle->image_ratio_y = true; //végrehajtás: kép átmozgatása végleges helyére $handle->Process($imagePath); if ($handle->processed) { //temp file törlése a szerverről $handle->clean(); $response = array("status" => 'success', "url" => $imagePath . $handle->file_dst_name, "width" => $handle->image_dst_x, "height" => $handle->image_dst_y); return json_encode($response); } else { $response = array("status" => 'error', "message" => $handle->error . ': Can`t upload File; no write Access'); return json_encode($response); } } else { $response = array("status" => 'error', "message" => $handle->error . ': Can`t upload File; no write Access'); return json_encode($response); } } // Kiválasztott kép vágása és vágott kép feltöltése if ($this->registry->params['id'] == 'crop') { // a croppic js küldi ezeket a POST adatokat $imgUrl = $_POST['imgUrl']; // original sizes $imgInitW = $_POST['imgInitW']; $imgInitH = $_POST['imgInitH']; // resized sizes //kerekítjük az értéket, mert lebegőpotos számot is kaphatunk és ez hibát okozna a kép generálásakor $imgW = round($_POST['imgW']); $imgH = round($_POST['imgH']); // offsets // megadja, hogy mennyit kell vágni a kép felső oldalából $imgY1 = $_POST['imgY1']; // megadja, hogy mennyit kell vágni a kép bal oldalából $imgX1 = $_POST['imgX1']; // crop box $cropW = $_POST['cropW']; $cropH = $_POST['cropH']; // rotation angle //$angle = $_POST['rotation']; //a $right_crop megadja, hogy mennyit kell vágni a kép jobb oldalából $right_crop = $imgW - $imgX1 - $cropW; //a $bottom_crop megadja, hogy mennyit kell vágni a kép aljából $bottom_crop = $imgH - $imgY1 - $cropH; // feltöltés helye $imagePath = Config::get('user.upload_path'); //képkezelő objektum létrehozása (a feltöltött kép elérése a paraméter) $handle = new Upload($imgUrl); // fájlneve utáni random karakterlánc $suffix = md5(uniqid()); if ($handle->uploaded) { // kép paramétereinek módosítása //$handle->file_auto_rename = true; //$handle->file_safe_name = true; //$handle->file_name_body_add = '_thumb'; $handle->file_new_name_body = "user_" . $suffix; //kép átméretezése $handle->image_resize = true; $handle->image_x = $imgW; $handle->image_ratio_y = true; //utána kép vágása $handle->image_crop = array($imgY1, $right_crop, $bottom_crop, $imgX1); //végrehajtás: kép átmozgatása végleges helyére $handle->Process($imagePath); if ($handle->processed) { // vágatlan forrás kép törlése az upload/user_photo mappából $handle->clean(); $response = array("status" => 'success', "url" => $imagePath . $handle->file_dst_name); return json_encode($response); } else { $response = array("status" => 'error', "message" => $handle->error . ': Can`t upload File; no write Access'); return json_encode($response); } } else { $response = array("status" => 'error', "message" => $handle->error . ': Can`t upload File; no write Access'); return json_encode($response); } } } }
/** * upload_remoto efetua o download/copia de uma imagem de outro servidor pra esse * @param string a url da imagem * @return string nome/endereço da imagem ou mensagem em caso de erro */ private function upload_remoto($url = '', $tipo = 'upload_remote') { $imgs = isset($_SESSION['imgs_upadas']) ? $_SESSION['imgs_upadas'] : array(); if (count($imgs) >= $this->__config['uploadMax']) { return '["' . $tipo . '", "erro", "' . $this->msgs['limite_uploads'] . '"]'; } $url = urldecode($url); if (!val('url', $url)) { return '["' . $tipo . '", "erro", "' . $this->msgs['url_invalido'] . '"]'; } $header = getheader($url); if (!is_array($header)) { return '["' . $tipo . '", "erro", "' . $this->msgs['servidor_nao_respondeu'] . '"]'; } if ($header['http_code'] != 200 && isset($this->__config['http_code'][$header['http_code']])) { $erro = str_replace('%file%', $url, $this->__config['http_code'][$header['http_code']]); return '["' . $tipo . '", "erro", "' . $erro . '"]'; } if (!isset($header['download_content_length']) || $header['download_content_length'] == 0) { return '["' . $tipo . '", "erro", "' . str_replace('%file%', $url, $this->msgs['servidor_nao_tamanho']) . '"]'; } if ($header['download_content_length'] > $this->__config['_tamanho']) { return '["' . $tipo . '", "erro", "' . $this->msgs['arquivo_muito_grande'] . '"]'; } $mime = $header['content_type']; $is_image = $this->is_image($mime); if (!$is_image) { return '["' . $tipo . '", "erro", "' . $this->msgs['arquivo_incorreto'] . '"]'; } $img = file_get_contents($url); if ($img) { $nome = gerar_nome_valido($is_image, $this->__config['diretorio']); if (file_put_contents($this->__config['diretorio'] . $nome, $img)) { require_once 'classes/upload/class.upload.php'; $new_img = new Upload($this->__config['diretorio'] . $nome, 'pt_BR'); $new_img->image_max_width = $this->__config['larguraMax']; $new_img->image_max_height = $this->__config['alturaMax']; $new_img->image_resize = $this->__config['resize']; $new_img->image_ratio_x = true; $new_img->image_ratio_y = true; $new_img->image_x = $this->__config['img_x']; $new_img->image_y = $this->__config['img_y']; $new_img->image_convert = $this->__config['convert_to']; $new_img->jpeg_quality = $this->__config['jpeg_quality']; $new_img->image_text = $this->__config['image_text']; $new_img->image_text_direction = $this->__config['image_text_direction']; $new_img->image_text_color = $this->__config['image_text_color']; $new_img->image_text_percent = $this->__config['image_text_percent']; $new_img->image_text_position = $this->__config['image_text_position']; $new_img->image_text_alignment = $this->__config['image_text_alignment']; $new_img->process($this->__config['diretorio']); if ($new_img->processed) { $new_img->clean(); clearstatcache(); $this->set($new_img->file_dst_name); return '["' . $tipo . '", "' . $new_img->file_dst_name . '"]'; } else { $new_img->clean(); @unlink($this->__config['diretorio'] . $new_img->file_dst_name); clearstatcache(); return '["' . $tipo . '", "erro", "' . $new_img->error . '"]'; } } else { return '["' . $tipo . '", "erro", "' . $this->msgs['nao_copio_image'] . '"]'; } } else { return '["' . $tipo . '", "erro", "' . $this->msgs['nao_copio_image'] . '"]'; } return '["' . $tipo . '", "erro", "' . $this->msgs['erro_desconhecido'] . '"]'; }
/** * Saves user profile data * * @param array $data entered user data * @param boolean $isNew true if this is a new user * @param boolean $result true if saving the user worked * @param string $error error message * * @return bool */ public function onUserAfterSave($data, $isNew, $result, $error) { //error_log("Akprofile::onUserAfterSave " . print_r($data,true) ); $userId = JArrayHelper::getValue($data, 'id', 0, 'int'); if ($userId && $result && isset($data['akprofile']) && count($data['akprofile'])) { try { // check if a new image is uploaded $handle = new Upload($_FILES['akprofile_image']); $handle->allowed = array('image/*'); if ($handle->uploaded && $handle->file_is_image) { $handle->image_convert = 'jpg'; $handle->jpeg_quality = 100; $handle->file_new_name_body = str_replace(' ', '_', strtolower($data['name'])) . '_' . $userId; $handle->file_overwrite = false; $handle->image_resize = true; $handle->image_x = 300; $handle->image_y = 300; $handle->image_ratio_crop = true; $savePath = JPATH_ROOT . '/images/userprofiles/'; $handle->process($savePath); if ($handle->processed) { $data['akprofile']['image'] = 'images/userprofiles/' . $handle->file_dst_name; $srcfile = $handle->file_src_pathname; $destfile = $savePath . $handle->file_dst_name_body . '_original.jpg'; // error_log("copying files. Src = " . $srcfile ) ; // error_log("copying files. destfile = " . $destfile ) ; JFile::copy($srcfile, $destfile); $handle->clean(); } else { error_log("Error processing user profile image for user " . $data['name'] . " error : " . $handle->error); } } // Sanitize the date //$data['akprofile']['dob'] = $this->date; $db = JFactory::getDbo(); $query = $db->getQuery(true)->delete($db->quoteName('#__user_profiles'))->where($db->quoteName('user_id') . ' = ' . (int) $userId)->where($db->quoteName('profile_key') . ' LIKE ' . $db->quote('akprofile.%')); $db->setQuery($query); $db->execute(); $tuples = array(); $order = 1; foreach ($data['akprofile'] as $k => $v) { $tuples[] = '(' . $userId . ', ' . $db->quote('akprofile.' . $k) . ', ' . $db->quote(json_encode($v)) . ', ' . $order++ . ')'; } $db->setQuery('INSERT INTO #__user_profiles VALUES ' . implode(', ', $tuples)); $db->execute(); } catch (RuntimeException $e) { $this->_subject->setError($e->getMessage()); return false; } } return true; }
/** * Kép adatainak módosítása * * * @param int $id * @return true vagy false */ public function update_photo($id) { $flag = false; if (isset($_FILES['upload_gallery_photo']) && $_FILES['upload_gallery_photo']['tmp_name'] != '') { // ******************* kép feltöltése ************************** // $flag = true; include LIBS . "/upload_class.php"; // feltöltés helye $imagePath = UPLOADS . "photo_gallery/"; //képkezelő objektum létrehozása (a kép a szerveren a tmp könyvtárba kerül) $handle = new Upload($_FILES['upload_gallery_photo']); if ($handle->uploaded) { $handle->allowed = array('image/*'); $random_number = md5(date('Y-m-d H:i:s:u')); $handle->jpeg_quality = 80; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = $this->photo_width; //kép szélessége; $handle->file_new_name_body = $random_number; //végrehajtás: kép átmozgatása végleges helyére $handle->Process($imagePath); $filename = $handle->file_dst_name; $data['photo_filename'] = UPLOADS . 'photo_gallery/' . $filename; if ($handle->processed) { $handle->jpeg_quality = 80; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = $this->thumb_width; // nézőkép szélessége $handle->file_new_name_body = $random_number . '_thumb'; //végrehajtás: kép átmozgatása végleges helyére $handle->Process($imagePath); $handle->clean(); } else { Message::set('error', 'Nem sikerült a feltöltés! Hiba: ' . $handle->error); return false; } } else { Message::set('error', 'Nem sikerült a feltöltés! Hiba: ' . $handle->error); return false; } } $data['photo_caption'] = $_POST['photo_caption']; $data['photo_category'] = $_POST['photo_category']; if (isset($_POST['photo_slider'])) { $data['photo_slider'] = $_POST['photo_slider']; } else { $data['photo_slider'] = 0; } $old_img = $_POST['old_photo']; /* var_dump($id); echo 'POST<br>'; var_dump($_POST); echo 'data:<br>'; var_dump($data); die(); */ // új adatok beírása az adatbázisba (update) a $data tömb tartalmazza a frissítendő adatokat $this->query->reset(); $this->query->set_table(array('photo_gallery')); $this->query->set_where('photo_id', '=', $id); $result = $this->query->update($data); if ($result) { if ($flag) { unlink($old_img); unlink(Util::thumb_path($old_img)); } Message::set('success', 'photo_update_success'); return true; } else { Message::set('error', 'unknown_error'); return false; } }
/** * Blog képet méretezi és tölti fel a szerverre (thumb képet is) * (ez a metódus az update() és insert() metódusokban hívódik meg!) * * @param $files_array Array ($_FILES['valami']) * @return String (kép elérési útja) or false */ private function upload_blog_picture($files_array) { include LIBS . "/upload_class.php"; // feltöltés helye $imagePath = UPLOADS . "images/"; //képkezelő objektum létrehozása (a kép a szerveren a tmp könyvtárba kerül) $handle = new Upload($files_array); //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 = "blog_" . rand(); $handle->image_resize = true; $handle->image_x = 600; $handle->image_y = 400; //$handle->image_ratio_y = true; //képarány meghatározása a nézőképhez $ratio = $handle->image_x / $handle->image_y; // Blog 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; } else { Message::set('error', $handle->error); return false; } // Nézőkép készítése // thumb mappába kerül a nézőkép $imagePath = UPLOADS . "images/thumb"; //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 = 150; $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 $dest_imagePath; }