protected function uploadFile() { if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $this->path)) { $path = $this->path; if (!$this->db->query("INSERT photo (name,folder,time,status) \n\t\t\tVALUES ('" . $this->name . "','" . $this->folder . "','" . time() . "','temp')")) { die("error"); } $id = $this->db->getLastId(); $this->image->load($path); $full = new SimpleImage(); $full->load($path); if ($full->getWidth() > 1200) { $full->resizeToWidth(1200); } $full->save(str_replace('.', '.full.', $path)); if ($this->image->getWidth() > 600) { $this->image->resizeToWidth(600); } $this->image->save($path); $size = $this->f->getFullSize($path, 90, 90); $img = array('name' => $this->name, 'path' => $path, 'count' => $this->getNum(), 'width' => $size['width'], 'height' => $size['height'], 'id' => $id); echo json_encode($img); } else { echo "error"; } }
function resizeImagesInFolder($dir, $i) { if (!is_dir('cover/' . $dir)) { toFolder('cover/' . $dir); } $files = scandir($dir); foreach ($files as $key => $file) { if ($file != '.' && $file != '..') { if (!is_dir($dir . '/' . $file)) { echo $dir . '/' . $file; $image = new SimpleImage(); $image->load($dir . '/' . $file); if ($image->getHeight() < $image->getWidth()) { $image->resizeToWidth(1920); } else { $image->resizeToHeight(1920); } // $new = 'cover/' . $dir . '/'.$image->name; if ($i < 10) { $new = 'cover/' . $dir . '/00' . $i . '.' . $image->type; } elseif ($i < 100) { $new = 'cover/' . $dir . '/0' . $i . '.' . $image->type; } else { $new = 'cover/' . $dir . '/' . $i . '.' . $image->type; } $image->save($new); echo ' ---------> ' . $new . '<br>'; $i++; } else { resizeImagesInFolder($dir . '/' . $file, 1); } } } }
function uploadArquivo($campoFormulario, $idGravado) { $ext = pathinfo($_FILES[$campoFormulario][name], PATHINFO_EXTENSION); if (($_FILES[$campoFormulario][name] <> "") && ($_FILES[$campoFormulario][size]) > 0 && in_array(strtolower($ext), $this->extensions)) { $arquivoTmp = $_FILES[$campoFormulario]['tmp_name']; $nome = str_replace(".", "", microtime(true)) . "_" . $_FILES[$campoFormulario]['name']; if (function_exists("exif_imagetype")) { $test = exif_imagetype($arquivoTmp); $image_type = $test; } else { $test = getimagesize($arquivoTmp); $image_type = $test[2]; } if (in_array($image_type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP))) { $image = new SimpleImage(); $image->load($arquivoTmp); $l = $image->getWidth(); $h = $image->getHeight(); if ($l > $h) { $funcao = "resizeToWidth"; $novoTamanho = 1024; } else { $funcao = "resizeToHeight"; $novoTamanho = 768; } $image->$funcao($novoTamanho); $copiou = $image->save($this->diretorio . $nome); if ($this->prefixoMarcaDagua) { $image->$funcao(300); $image->watermark(); $image->save($this->diretorio . $this->prefixoMarcaDagua . $nome); } if ($this->prefixoMiniatura) { $image->load($arquivoTmp); $image->$funcao(380); $image->save($this->diretorio . $this->prefixoMiniatura . $nome); } } else { $copiou = copy($arquivoTmp, $this->diretorio . $nome); } if ($copiou) { $sql = "update $this->tabela set $this->campoBD = '$nome' where id='$idGravado'"; #$altualizaNome = mysql_query($sql) or die($sql . mysql_error); $this->conexao->executeQuery($sql); } } else { return false; } return $idGravado; }
private static function base64ToLocalImage($img, $path, $lim = false, $saveas = '', $quality = 75) { $imgdata = base64_decode($img); if (!!$imgdata) { require_once 'Master/base/libraries/Images/SimpleImage.php'; $str = str_replace('data:', '', $img); $arr = explode(';', $str); $type = $arr[0]; $data = str_replace('base64,', '', $arr[1]); $data = base64_decode($data); $ext = static::getExt($type); if (!!$data && !!$ext) { $name = !!$saveas ? $saveas : Bella::createId(32); $name .= $ext; $file = $path . $name; $save = @file_put_contents($file, $data); if (!!$save) { $sm = new SimpleImage(); $sm->load($file); $w = $sm->getWidth(); $h = $sm->getHeight(); $minWidth = static::MIN_WIDTH; $minHeight = static::MIN_HEIGHT; $maxWidth = static::MAX_WIDTH; $maxHeight = static::MAX_HEIGHT; if (!!$lim) { if (isset($lim['minWidth'])) { $minWidth = $lim['minWidth']; } if (isset($lim['minHeight'])) { $minHeight = $lim['minHeight']; } if (isset($lim['maxWidth'])) { $maxWidth = $lim['maxWidth']; } if (isset($lim['maxHeight'])) { $maxHeight = $lim['maxHeight']; } } if ($w < $minWidth || $h < $minHeight) { unlink($file); return false; } if ($w > $maxWidth || $h > $maxHeight) { $sm->fillTo($maxWidth, $maxHeight); $sm->save($file, false, $quality); } return $name; } } } }
public function bindImage($elementName) { $file = JRequest::getVar($elementName, '', 'FILES'); if (!isset($file['tmp_name']) || empty($file['tmp_name'])) { return false; } jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); // @task: Test if the folder containing the badges exists if (!JFolder::exists(DISCUSS_BADGES_PATH)) { JFolder::create(DISCUSS_BADGES_PATH); } // @task: Test if the folder containing uploaded badges exists if (!JFolder::exists(DISCUSS_BADGES_UPLOADED)) { JFolder::create(DISCUSS_BADGES_UPLOADED); } require_once DISCUSS_CLASSES . '/simpleimage.php'; $image = new SimpleImage(); $image->load($file['tmp_name']); if ($image->getWidth() > 64 || $image->getHeight() > 64) { return false; } $storage = DISCUSS_BADGES_UPLOADED; $name = md5($this->id . DiscussHelper::getDate()->toMySQL()) . $image->getExtension(); // @task: Create the necessary path $path = $storage . '/' . $this->id; if (!JFolder::exists($path)) { JFolder::create($path); } // @task: Copy the original image into the storage path JFile::copy($file['tmp_name'], $path . '/' . $name); // @task: Resize to the 16x16 favicon $image->resize(DISCUSS_BADGES_FAVICON_WIDTH, DISCUSS_BADGES_FAVICON_HEIGHT); $image->save($path . '/' . 'favicon_' . $name); $this->avatar = $this->id . '/' . $name; $this->thumbnail = $this->id . '/' . 'favicon_' . $name; return $this->store(); }
$tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/rb72aknjykn0w5cefu6z3g7yw8xnpa/'; $targetFile = str_replace('//', '/', $targetPath) . $file; $name = $_FILES['Filedata']['name']; error_reporting(0); // $fileTypes = str_replace('*.','',$_REQUEST['fileext']); // $fileTypes = str_replace(';','|',$fileTypes); // $typesArray = split('\|',$fileTypes); // $fileParts = pathinfo($_FILES['Filedata']['name']); // if (in_array($fileParts['extension'],$typesArray)) { // Uncomment the following line if you want to make the directory if it doesn't exist mkdir(str_replace('//', '/', $targetPath), 0755, true); move_uploaded_file($tempFile, $targetFile); $image = new SimpleImage(); $image->load($targetFile); if ($image->getWidth() > 600 || $image->getHeight() > 450) { //set proper width if ($image->getWidth() > 600) { $image->resizeToWidth(600); } //set proper height if ($image->getHeight() > 450) { $image->resizeToHeight(450); } $image->save($targetFile, IMAGETYPE_JPEG, 75, 0755); $newFile = str_replace('//', '/', $targetPath) . 'thumb_' . $file; $image->resize(155, 115); $image->save($newFile, IMAGETYPE_JPEG, 75, 0755); } else { $image->save($targetFile, IMAGETYPE_JPEG, 75, 0755); $newFile = str_replace('//', '/', $targetPath) . 'thumb_' . $file;
/** * Get file (photo) from POST and save it * following the http://forum.joomla.org/viewtopic.php?t=650699 guidelines... override save on model... */ public function save($data) { if (empty($data['userid'])) { //that means NON mobile.json version (mobile.json sends uid already filled) $data = JRequest::getVar('jform', array(), 'post', 'array'); $uidPath = JFactory::getUser()->get('id'); } else { $uidPath = $data['userid']; } $file = JRequest::getVar('jform', array(), 'files', 'array'); $app = JFactory::getApplication(); $params = $app->getParams(); $approval = $params->get('approveissue'); $data['state'] = !$approval; if ($approval == 1) { JFactory::getApplication()->enqueueMessage(JText::_('COM_IMPROVEMYCITY_APPROVAL_PENDING')); } if ($file) { //Cannot use makeSafe with non-english characters (or better only ascii is supported) //$filename = JFile::makeSafe($file['name']['photo']); //use custom makeSafe instead... $filename = $this->stringURLSafe($file['name']['photo']); if ($filename != '') { if ($file['type']['photo'] != 'image/jpeg' && $file['type']['photo'] != 'image/png') { $this->setError(JText::_('ONLY_PNG_JPG')); return false; } $src = $file['tmp_name']['photo']; $dest = JPATH_SITE . DS . "images" . DS . "improvemycity" . DS . $uidPath . DS . "images" . DS . $filename; $thumb_dest = JPATH_SITE . DS . "images" . DS . "improvemycity" . DS . $uidPath . DS . "images" . DS . "thumbs" . DS . $filename; //resize image here include_once JPATH_COMPONENT . '/helpers/simpleimage.php'; $image = new SimpleImage(); $image->load($src); $width = $image->getWidth(); $height = $image->getHeight(); $new_height = $height; $new_width = $width; $target_width = 800; //TODO: GET FROM PARAMETERS $target_height = 600; //TODO: GET FROM PARAMETERS $target_ratio = $target_width / $target_height; $img_ratio = $width / $height; if ($target_ratio > $img_ratio) { $new_height = $target_height; $new_width = $img_ratio * $target_height; } else { $new_height = $target_width / $img_ratio; $new_width = $target_width; } if ($new_height > $target_height) { $new_height = $target_height; } if ($new_width > $target_width) { $new_height = $target_width; } if ($width > $target_width && $height > $target_height) { if ($new_height != $height || $new_width != $width) { $image->resize($new_width, $new_height); $image->save($src); } } //always use constants when making file paths, to avoid the possibilty of remote file inclusion if (!JFile::upload($src, $dest)) { echo JText::_('ERROR MOVING FILE'); return; } else { // success, exit with code 0 for Mac users, otherwise they receive an IO Error JPath::setPermissions($dest); //CREATE THUMBNAIL HERE $image->load($dest); $image->resize(80, 60); //TODO: GET FROM PARAMETERS $pathToThumb = JPATH_SITE . DS . 'images' . DS . 'improvemycity' . DS . $uidPath . DS . 'images' . DS . 'thumbs'; if (!JFolder::exists($pathToThumb)) { JFolder::create($pathToThumb); } //$thumb = $pathToThumb.DS.$fileName; $image->save($thumb_dest); JPath::setPermissions($thumb_dest); //update data with photo path $data['photo'] = 'images/improvemycity/' . $uidPath . '/images/thumbs/' . $filename; //$data['thumb'] = 'images/improvemycity/'.J$uidPath.'/images/thumbs/'.$filename; //$data['photo'] = 'images'.'/'.'improvemycity'.'/'.$uidPath.'/'.'images'.'/'.$fileName; } /* if (JFile::upload($src, $dest, false) ){ //update data with photo path $data['photo'] = 'images/improvemycity/'.$uidPath.'/images/'.$filename; } */ } } // Initialise variables; $dispatcher = JDispatcher::getInstance(); $table = $this->getTable(); $key = $table->getKeyName(); $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id'); $isNew = true; // Include the content plugins for the on save events. JPluginHelper::importPlugin('content'); // Allow an exception to be thrown. try { // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // Clean the cache. $this->cleanCache(); // Trigger the onContentAfterSave event. $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew)); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } $pkName = $table->getKeyName(); if (isset($table->{$pkName})) { $this->setState($this->getName() . '.id', $table->{$pkName}); } $this->setState($this->getName() . '.new', $isNew); //update timestamp $this->updateTimestamp(); //notify admins and user $this->notifyByEmail($table->id, $data); return $table->id; //return true; }
function addPictures($categoryid) { global $db, $login, $config; $c = (int) $categoryid; $category = getCategory($c); $folder = $category['uniqid']; $path = 'media/images/' . $folder . '/'; @mkdir($path, 0777); @chmod($path, 0777); $upload = new Upload(); $upload->dir = $path; if ($config->get('media', 'max-upload-size') > 0) { $upload->max_byte_size = $config->get('media', 'max-upload-size'); } else { $upload->max_byte_size = 10485760; } $result = $upload->uploadArray(); // Resize image if too large if ($config->get('media', 'auto-resize') != 0) { $max_width = (int) $config->get('media', 'auto-resize-width'); if ($max_width == 0) { $max_width = 1024; } $image = new SimpleImage(); for ($i = 0; $i < count($_FILES['file']['name']); $i++) { if (file_exists($path . $_FILES['file']['name'][$i])) { $image->load($path . $_FILES['file']['name'][$i]); if ($image->getWidth() > $max_width) { $image->resizeToWidth($max_width); unlink($path . $_FILES['file']['name'][$i]); $image->save($path . $_FILES['file']['name'][$i]); } } } } }
if (!is_dir(AT_PA_CONTENT_DIR . $album_file_path_tn)) { mkdir(AT_PA_CONTENT_DIR . $album_file_path_tn); } //add the photo $added_photo_id = $pa->addPhoto($_FILES['photo']['name'], $_POST['photo_comment'], $_SESSION['member_id']); if ($added_photo_id <= 0) { $msg->addError('PA_ADD_PHOTO_FAILED'); } if (!$msg->containsErrors()) { //get photo filepath $photo_info = $pa->getPhotoInfo($added_photo_id); $photo_file_path = getPhotoFilePath($added_photo_id, $_FILES['photo']['name'], $photo_info['created_date']); //resize images to a specific size, and its thumbnail $si = new SimpleImage(); $si->load($_FILES['photo']['tmp_name']); $image_w = $si->getWidth(); $image_h = $si->getHeight(); //picture is horizontal if ($image_w > $image_h) { //don't stretch images if ($image_w > AT_PA_IMAGE) { $si->resizeToWidth(AT_PA_IMAGE); $si->save(AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path); } else { move_uploaded_file($_FILES['photo']['tmp_name'], AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path); } $si->resizeToWidth(AT_PA_IMAGE_THUMB); $si->save(AT_PA_CONTENT_DIR . $album_file_path_tn . $photo_file_path); } else { if ($image_h > AT_PA_IMAGE) { $si->resizeToHeight(AT_PA_IMAGE);
/** * Watermarks an image * * @param string $source Watermark image path * @param string $position Position on image (can be top-left, top right, bottom-right, bottom-left) * * @return void */ public function waterMark($source, $position = 'bottom-left') { // Watermark margins: $margins = 5; // Getting the waterMark image: $w = new SimpleImage(); $w->load($source); // Getting the watermark position: switch ($position) { case 'top-left': $startX = $margins; $startY = $margins; break; case 'top-right': $startX = $this->getWidth() - $w->getWidth() - $margins; $startY = $margins; break; case 'bottom-right': $startX = $this->getWidth() - $w->getWidth() - $margins; $startY = $this->getHeight() - $w->getHeight() - $margins; break; // Bottom left: // Bottom left: default: $startX = $margins; $startY = $this->getHeight() - $w->getHeight() - $margins; break; } $newImage = $this->currentImage; imagecopy($newImage, $w->currentImage, $startX, $startY, 0, 0, $w->getWidth(), $w->getHeight()); $this->currentImage = $newImage; }
public function executeAvatar(HTTPRequest $request) { ini_set("memory_limit", '256M'); $this->page->smarty()->assign('avatar', $this->_profilePro->getAvatar()); if ($request->fileExists('avatar')) { $avatar = $request->fileData('avatar'); if ($avatar['error'] == 0) { $simpleImage = new SimpleImage(); $simpleImage->load($avatar['tmp_name']); if (!is_null($simpleImage->image_type)) { $height = $simpleImage->getHeight(); $width = $simpleImage->getWidth(); if ($height > $width) { $simpleImage->resizeToHeight(150); } else { $simpleImage->resizeToWidth(150); } $filename = time() . '.jpg'; $simpleImage->save($_SERVER['DOCUMENT_ROOT'] . $this->_userDir . $filename); if ($this->_profilePro->getAvatar() != ProfilePro::AVATAR_DEFAULT_PRO) { unlink($_SERVER['DOCUMENT_ROOT'] . $this->_profilePro->getAvatar()); } $this->_profilePro->setAvatar($this->_userDir . $filename); $this->_profileProManager->save($this->_profilePro); $this->app->user()->setFlash('avatar-updated'); } else { $this->app->user()->setFlash('avatar-error'); } } else { $this->app->user()->setFlash('avatar-error'); } $this->app->httpResponse()->redirect('/profile-pro'); } }
// propose a filename $exists = TRUE; while ($exists) { $filename = uniqid(rand(), true) . "." . $ext; if (file_exists("../user_content/" . $filename)) { $exists = TRUE; } else { $exists = FALSE; } } move_uploaded_file($_FILES["files"]["tmp_name"][$key], "../user_content/" . $filename); // copy the uploaded file to proper directory if (file_exists("../user_content/" . $filename)) { $image = new SimpleImage(); $image->load('../user_content/' . $filename); if ($image->getWidth() > $image->getHeight()) { $image->resizeToWidth(80); } else { $image->resizeToHeight(80); } $image->save('../user_content/thumbs/' . $filename); $db->query("INSERT INTO photos (listing_id, filename) VALUES ('{$listing_id}','{$filename}')"); // insert db association } //echo "<a href=\"/uploads/articles/{$_POST['article_id']}.{$ext}\" target=\"_blank\">View Word Document</a>"; // is never shown to the user, debug purpose } } } } if (isset($_GET['id'])) { if (file_exists("../uploads/articles/" . $_GET['id'] . ".doc")) {
// php library for image files management. include '../SimpleImage.php'; $DOC_FILE1 = $_FILES['portada']['tmp_name']; $DOC_FILE_NAME1 = $_FILES['portada']['name']; // code to resample and upload image file. if ($DOC_FILE1 != NULL) { $photos_download_dir = "../../imgs/galeria/evento_" . $next_slide . "/"; // create the new directory if it doesn't exist. if (!file_exists($photos_download_dir)) { mkdir($photos_download_dir, 0777, true); } // change spaces to underscores in filename $photo_name = 'portada.jpg'; $photo_big = new SimpleImage(); $photo_big->load($DOC_FILE1); if ($photo_big->getWidth() > 2080 || $photo_big->getHeight() > 1388) { if ($photo_big->getWidth() > 2080) { $photo_big->resizeToWidth(2080); } if ($photo_big->getHeight() > 1388) { $photo_big->resizeToHeight(1388); } } // save the photo into the videogallery directory. $photo_big->save($photos_download_dir . $photo_name, $DOC_FILE_TYPE1); //END CODE TO RESAMPLE AND UPLOAD PHOTO FILE. } unlink($DOC_FILE1); $insertSQL = "INSERT INTO eventos (id_evento, nombre, descripcion, portada, fecha_ini, fecha_fin) VALUES ('" . $next_slide . "','" . $_POST['nombre'] . "','" . $_POST['descripcion'] . "','" . $photo_name . "','" . $_POST['fecha_ini'] . "','" . $_POST['fecha_fin'] . "')"; $Result1 = mysql_query($insertSQL, $elencuentro) or die(mysql_error()); header("Location: index.php");
$ad['url'] = "http://" . $ad['url']; } $db->update($tbl_ad, "url='" . $ad['url'] . "'", "adid=" . $id); } } } if ($_FILES['image']['size'] > 0) { $upload = new Upload(); $upload->dir = 'media/boximages/ad/'; $upload->tag_name = 'image'; $upload->uploadFile(); $imgdir = "./media/boximages/ad/"; include_once './core/simple.image.core.php'; $image = new SimpleImage(); $image->load($imgdir . $upload->file_name); if ($image->getWidth() > (int) $config->get('ad', 'standard_image_width')) { $image->resizeToWidth((int) $config->get('ad', 'standard_image_width')); } if ($image->getHeight() > (int) $config->get('ad', 'standard_image_height')) { $image->resizeToHeight((int) $config->get('ad', 'standard_image_height')); } unlink($imgdir . $upload->file_name); $image->save($imgdir . $upload->file_name); if (substr($_POST['newurl'], 0, 7) != "http://") { $_POST['newurl'] = "http://" . $_POST['newurl']; } $db->insert($tbl_ad, array('img', 'url'), array("'" . $upload->file_name . "'", "'" . $_POST['newurl'] . "'")); } } $allads = $db->selectList($tbl_ad, '*', 1); $counter = 0;
function upload($userid, $max_byte_size = 2097152) { global $debug; global $config; $dir = 'media/avatar/'; $msg = ''; // upload button has been pressed if (@$_POST['submit'] == 'Upload') { // set allowed file types $allowed_types = "(jpg|jpeg|gif|bmp|png)"; // is really a file? if (is_uploaded_file($_FILES["file"]["tmp_name"])) { // valid extension? if (preg_match("/\\." . $allowed_types . "\$/i", $_FILES["file"]["name"])) { // file size okay? if ($_FILES["file"]["size"] <= $max_byte_size) { // width and height okay? $size = getimagesize($_FILES['file']['tmp_name']); $debug->add('img-size', 'height:' . $size[0] . ' width:' . $size[1]); // get user $u = $this->user->getUserByID($userid); $filename = uniqid($u['userid'] . "_") . "_" . $_FILES["file"]["name"]; // everything all right, now copy if (!file_exists($dir . $filename)) { if (copy($_FILES["file"]["tmp_name"], $dir . $filename)) { // Resize image if too large $image = new SimpleImage(); $image->load($dir . $filename); if ($image->getWidth() > (int) $config->get('core', 'img-width')) { $image->resizeToWidth((int) $config->get('core', 'img-width')); } if ($image->getHeight() > (int) $config->get('core', 'img-height')) { $image->resizeToHeight((int) $config->get('core', 'img-height')); } // Save image $this->remove($filename); $image->save($dir . $filename); // upload successfull $msg = $this->lang->get('upload_successfull'); // remove old avatar $this->remove($u['avatar']); // update avatar $this->user->setAvatar($userid, $filename); } else { $msg = $this->lang->get('upload_failed'); } } else { $msg = $this->lang->get('upload_failed'); } } else { $msg = $this->lang->get('upload_too_large'); } } else { $msg = $this->lang->get('upload_bad_extension'); } } else { $msg = $this->lang->get('upload_failed'); } } // display the upload-form return ' <p> ' . $msg . ' </p> <form action="" method="post" enctype="multipart/form-data" name="upload"> <input type="file" name="file" /> <input type="submit" name="submit" value="Upload" /> </form> '; }
//_pr(get_bloginfo('stylesheet_directory').'/img/header-perfil-publico.png'); $perfil_header = get_user_meta($curauth->ID, '_header_css', true); if (!$perfil_header) { $perfil_header = array('color' => '', 'image_url' => get_bloginfo('stylesheet_directory') . '/img/header-perfil-publico.png', 'exibir_nome' => true, 'font-color' => '#000000', 'text_position' => 'top-left'); add_user_meta($curauth->ID, "_header_css", $perfil_header); } if ($widget_group->editable() && isset($_POST['tnb_header_action']) && ($_POST['tnb_header_action'] = "save")) { $acceptedFormats = array('image/gif', 'image/png', 'image/jpeg', 'image/pjpeg', 'image/x-png'); if (isset($_FILES['header_image']) and in_array($_FILES['header_image']['type'], $acceptedFormats)) { //_pr($_FILES,true); require_once ABSPATH . '/wp-admin/includes/file.php'; require_once ABSPATH . '/wp-admin/includes/media.php'; require_once ABSPATH . '/wp-admin/includes/image.php'; $si = new SimpleImage(); $si->load($_FILES['header_image']['tmp_name']); if ($si->getWidth() > 922) { $si->resizeToWidth(922); $si->save($_FILES['header_image']['tmp_name'], $si->image_type, 100); } $post_data = array('post_author' => $curauth->ID, 'post_title' => 'header_background_image'); $postid = media_handle_upload('header_image', null, $post_data); add_post_meta($postid, '_image_type', 'header'); $perfil_header['image_url'] = wp_get_attachment_url($postid); } elseif ($_POST['color'] != $perfil_header['color']) { $perfil_header['color'] = $_POST['color']; $perfil_header['image_url'] = ''; } $perfil_header['exibir_nome'] = isset($_POST['exibir_nome']); if ($_POST['font_color'] != $perfil_header['font-color']) { $perfil_header['font-color'] = $_POST['font_color']; }
function try_thumb($base) { global $globals; $final_size = Link::thumb_sizes($base); if (!$final_size) { return false; } $dir = Upload::get_cache_dir($this->id); $output_filename = "{$base}-{$this->id}.jpg"; require_once mnminclude . "simpleimage.php"; $f = false; $input = new SimpleImage(); foreach (Link::thumb_sizes() as $b => $s) { if ($b == 'thumb') { $delete = true; // Mark as deleted if the last does not exist $root = ""; } else { $delete = false; $root = $b; } $filename = "{$root}-{$this->id}.jpg"; // Check first if the file exists if (is_readable("{$dir}/{$filename}")) { $f = "{$dir}/{$filename}"; } else { $f = $this->thumb_download($b, $delete); } if ($f && $input->load($f)) { break; } } if (!$input->image) { return false; } if ($input->getWidth() <= $final_size) { if ($f != "{$dir}/{$output_filename}") { copy($f, "{$dir}/{$output_filename}"); } } else { $input->resize($final_size, $final_size); $input->save("{$dir}/{$output_filename}"); } @chmod($f, 0777); @chmod("{$dir}/{$output_filename}", 0777); return "{$dir}/{$output_filename}"; }
public function fixPhoto($filename,$filenamepre,$filenamethb) { $image = new SimpleImage(); // instantiate image manipulation class $image->load($filenamepre); // load source image if (($image->getWidth()>$this->settings->previewwidth) || ($image->getHeight()>$this->settings->previewheight)) { $image->load($filename); // load source image $image->resizepic( $this->settings->previewwidth, $this->settings->previewheight ); // resize to height as desired in technical requirements $image->save($filenamepre); // save resized file to disk } $image->load($filenamethb); // load source image if (($image->getWidth()>$this->settings->thumbwidth) || ($image->getHeight()>$this->settings->thumbheight)) { $image->load($filename); // load source image $image->resizepic( $this->settings->thumbwidth, $this->settings->thumbheight ); // resize to height as desired in technical requirements $image->save($filenamethb); // save resized file to disk } }
$tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; $targetFile = str_replace('//', '/', $targetPath) . $_FILES['Filedata']['name']; $name = $_FILES['Filedata']['name']; error_reporting(0); // $fileTypes = str_replace('*.','',$_REQUEST['fileext']); // $fileTypes = str_replace(';','|',$fileTypes); // $typesArray = split('\|',$fileTypes); // $fileParts = pathinfo($_FILES['Filedata']['name']); // if (in_array($fileParts['extension'],$typesArray)) { // Uncomment the following line if you want to make the directory if it doesn't exist mkdir(str_replace('//', '/', $targetPath), 0755, true); move_uploaded_file($tempFile, $targetFile); $image = new SimpleImage(); $image->load($targetFile); if ($image->getWidth() >= 600) { $newFile = str_replace('//', '/', $targetPath) . "full_" . $name; $image->resizeToWidth(600); $image->save($newFile, IMAGETYPE_JPEG, 75, 0755); $newFile = str_replace('//', '/', $targetPath) . "thumb_" . $name; $image->resizeToHeight(32); $image->save($newFile, IMAGETYPE_JPEG, 75, 0755); } else { $newFile = str_replace('//', '/', $targetPath) . "full_" . $name; $image->save($newFile, IMAGETYPE_JPEG, 75, 0755); $newFile = str_replace('//', '/', $targetPath) . "thumb_" . $name; $image->resizeToHeight(32); $image->save($newFile, IMAGETYPE_JPEG, 75, 0755); } //echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile); echo $name;
function uploadImage($fileID, $directory, $imageWidth = NULL, $imageHeight = NULL, $thumbWidth = NULL, $thumbHeight = NULL) { /* echo "imageWidth = |" . $imageWidth . "|<br />"; echo "imageHeight = |" . $imageHeight . "|<br />"; echo "thumbWidth = |" . $thumbWidth . "|<br />"; echo "thumbHeight = |" . $thumbHeight . "|<br />"; */ $FILE = $_FILES[$fileID]['tmp_name']; $FILE_NAME = $_FILES[$fileID]['name']; $fileName_final = cleanForShortURL($FILE_NAME); if ($FILE != NULL) { //////////// BIG IMAGE ///////////////////////////////////////////////////////// // If big image is required. if ($imageWidth != NULL || $imageHeight != NULL) { if (is_numeric($imageWidth) || is_numeric($imageHeight)) { // resample image $image = new SimpleImage(); $image->load($FILE); if (is_numeric($imageWidth) && is_numeric($imageHeight)) { if ($image->getWidth() > $imageWidth || $image->getHeight() > $imageHeight) { if ($image->getWidth() > $imageWidth) { $image->resizeToWidth($imageWidth); } if ($image->getHeight() > $imageHeight) { $image->resizeToHeight($imageHeight); } } } else { if (is_numeric($imageWidth) && !is_numeric($imageHeight)) { if ($image->getWidth() > $imageWidth) { $image->resizeToWidth($imageWidth); } } else { if (!is_numeric($imageWidth) && is_numeric($imageHeight)) { if ($image->getHeight() > $imageHeight) { $image->resizeToHeight($imageHeight); } } } } // if directory doesn't exist, it is created. if (!file_exists($directory)) { mkdir($directory, 0777, true); } // save image into directory. $image->save($directory . $fileName_final); } // close: if(!is_numeric($imageWidth) && !is_numeric($imageHeight)) } else { //Subimos la imagen con sus dimensiones originales (sin resize) // if directory doesn't exist, it is created. if (!file_exists($directory)) { mkdir($directory, 0777, true); } move_uploaded_file($FILE, $directory . $fileName_final); // Moving Uploaded imagen } //////////// THUMBNAIL ///////////////////////////////////////////////////////// // If thumbnail is required. if ($thumbWidth != NULL || $thumbHeight != NULL) { if (is_numeric($thumbWidth) || is_numeric($thumbHeight)) { // resample thumbnail $thumb = new SimpleImage(); $thumb->load($FILE); if (is_numeric($thumbWidth) && is_numeric($thumbHeight)) { if ($thumb->getWidth() > $thumbWidth || $thumb->getHeight() > $thumbHeight) { if ($thumb->getWidth() > $thumbWidth) { $thumb->resizeToWidth($thumbWidth); } if ($thumb->getHeight() > $thumbHeight) { $thumb->resizeToHeight($thumbHeight); } } } else { if (is_numeric($thumbWidth) && !is_numeric($thumbHeight)) { if ($thumb->getWidth() > $thumbWidth) { $thumb->resizeToWidth($thumbWidth); } } else { if (!is_numeric($thumbWidth) && is_numeric($thumbHeight)) { if ($thumb->getHeight() > $thumbHeight) { $thumb->resizeToHeight($thumbHeight); } } } } $thumbnailsDirectory = $directory . "thumbs/"; // if directory doesn't exist, it is created. if (!file_exists($thumbnailsDirectory)) { mkdir($thumbnailsDirectory, 0777, true); } // save thumb into thumbnails directory. $thumb->save($thumbnailsDirectory . $fileName_final); } // close: if(!is_numeric($thumbWidth) && !is_numeric($thumbHeight)) } // close: if($thumbWidth != NULL || $thumbHeight != NULL) //////////// THUMBNAIL ENDS HERE ///////////////////////////////////////////////// // delete temporary uploaded file. unlink($FILE); return $fileName_final; } else { // close: if($FILE != NULL) return NULL; } }
if (!in_array($fileExt, $typesArray)) { die("error_filetype_not_allowed"); } $relative_folder_path = "files/" . gmdate("Y-m") . "/images"; $absolute_folder_path = str_replace('//', '/', "{$_SESSION["root_path"]}/{$relative_folder_path}"); if (!is_dir($absolute_folder_path)) { mkdir($absolute_folder_path, 0755, true); } $random_fileNumber = gmdate("U_") . rand(0, 1000); $filename = "{$random_fileNumber}__{$user->username}___{$fileParts['basename']}"; $file_absolute_path_fullsize = "{$absolute_folder_path}/{$filename}"; $file_absolute_path_thumbnail = "{$absolute_folder_path}/tn_{$filename}"; $file_relative_path_fullsize = "{$relative_folder_path}/{$filename}"; $file_relative_path_thumbnail = "{$relative_folder_path}/tn_{$filename}"; copy($_FILES['Filedata']['tmp_name'], $file_absolute_path_thumbnail); move_uploaded_file($_FILES['Filedata']['tmp_name'], $file_absolute_path_fullsize); $img = new SimpleImage(); $img->load($file_absolute_path_thumbnail); $filetype = $img->image_type; if ($img->getWidth() > $img->getHeight()) { $img->resizeToWidth(150); } else { $img->resizeToHeight(150); } $img->save($file_absolute_path_thumbnail, $filetype); $group = $_REQUEST["group"]; $created = gmdate("Y-m-d H:i:s"); if (!mysql_query("INSERT INTO `images_general` (`type`,`size`,`file_location`,`file_thumbnail`,`file_name`,`group`,`author`,`created`) VALUES ('{$fileExt}','" . filesize($_FILES['Filedata']['tmp_name']) . "','{$file_relative_path_fullsize}','{$file_relative_path_thumbnail}','{$fileParts['basename']}','{$group}','{$user->username}','{$created}')")) { die("database_error"); } die("done");
$data['error'] = "OK"; $data['message'] = $LANG['Image_delete_OK']; } if ($action == 'uploadImg') { if (!isset($bugID)) { throw new Exception("uploadImg: bug's ID is missing!"); } $fname = $_FILES['file']['name']; if (file_exists(DATA_PATH . $fname)) { $fname = date('Ymd-His_') . $fname; } if (!move_uploaded_file($_FILES['file']['tmp_name'], DATA_PATH . $fname)) { throw new Exception("Uploaded file could not be moved to data folder."); } $image = new SimpleImage(DATA_PATH . $fname); if ($image->getWidth() > 1200) { $image->resizeToWidth(1200); $image->save(DATA_PATH . $fname); } if ($bugID !== "newBug") { $b = new Bug((int) $bugID); $b->addImage($fname); } $data['img'] = $fname; $data['error'] = "OK"; $data['message'] = $LANG['Image_add_OK']; } } catch (Exception $e) { $data['message'] = $e->getMessage(); $data['trace'] = $e->getTrace(); }
private function savePhoto(AnnouncementPro $announce, $target, $file) { if ($file['error'] == 0) { $simpleImage = new SimpleImage(); $thumbnailsSimpleImage = new SimpleImage(); $simpleImage->load($file['tmp_name']); $thumbnailsSimpleImage->load($file['tmp_name']); if (!is_null($simpleImage->image_type)) { $height = $simpleImage->getHeight(); $width = $simpleImage->getWidth(); //Redimensionnement de l'image original en format modéré if ($height > 1200 || $width > 1600) { if ($height > $width) { $simpleImage->resizeToHeight(1200); } else { $simpleImage->resizeToWidth(1600); } } //Redimensionnement de l'image original en miniature if ($height > $width) { $thumbnailsSimpleImage->resizeToHeight(300); } else { $thumbnailsSimpleImage->resizeToWidth(300); } $filename = $target . '-' . time() . '.jpg'; $thumbnails = AnnouncementPro::THUMBNAILS_PREFIX . $filename; $simpleImage->save($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $filename); $thumbnailsSimpleImage->save($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $thumbnails); $getMethod = 'get' . $target; $setMethod = 'set' . $target; if ($announce->{$getMethod}() != AnnouncementPro::IMAGE_DEFAULT && $announce->{$getMethod}() != '') { unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $announce->{$getMethod}()); unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . AnnouncementPro::THUMBNAILS_PREFIX . $announce->{$getMethod}()); } $announce->{$setMethod}($filename); } } }
$item = 'picture_file_' . $i; if (isset($_FILES[$item])) { $target_path = '/tmp/'; $target_path = $target_path . basename($_FILES[$item]['name']); // Mime Type Check $mime = mime_content_type($_FILES[$item]['tmp_name']); $accepted_mimes = array('image/jpeg', 'image/gif', 'image/png'); if (!in_array($mime, $accepted_mimes)) { array_push($errors, 'You attempted to upload an unsupported image type, or you did not select an image. Please try uploading a JPEG, PNG or GIF.'); } if (count($errors) == 0) { if (move_uploaded_file($_FILES[$item]['tmp_name'], $target_path)) { //bookmark $resizeimage = new SimpleImage(); $resizeimage->load($target_path); if ($resizeimage->getWidth() > $resizeimage->getHeight()) { if ($resizeimage->getWidth() > 800) { $resizeimage->resizeToWidth(800); } } else { if ($resizeimage->getHeight() > 800) { $resizeimage->resizeToHeight(800); } } $resizeimage->save($target_path); $ext = substr($target_path, strpos($target_path, ".") + 1); $ext = str_replace(".", "", $ext); $name = $meta['experiment_id'] . '_' . $session->userid . '_' . time() . '_' . $i . '.' . $ext; $s3->putObjectFile($target_path, AWS_IMG_BUCKET, $name, S3::ACL_PUBLIC_READ); $provider_url = $url . '/' . $name; createImageItemWithSessionId($session->userid, $meta['experiment_id'], $sid, "iSENSE - " . $vtitle, $description, 'Amazon S3', $name, $provider_url, AWS_IMG_BUCKET, 1);
function upload() { if (!isset($_FILES['upload'])) { $this->directrender('S3/S3'); return; } global $params; // Params to vars $client_id = '1b5cc674ae2f335'; // Validations $this->startValidations(); $this->validate($_FILES['upload']['error'] !== 1, $err, 'size too large'); $this->validate($_FILES['upload']['error'] === 0, $err, 'upload error'); $this->validate($_FILES['upload']['size'] <= 10 * 1024 * 1024, $err, 'size too large'); // Code if ($this->isValid()) { $fname = $_FILES['upload']['tmp_name']; require_once $GLOBALS['dirpre'] . 'includes/S3/SimpleImage.php'; $image = new SimpleImage(); $this->validate($image->load($fname), $err, 'invalid image type'); if ($this->isValid()) { if ($image->getHeight() < $image->getWidth()) { if ($image->getHeight() > 1000) { $image->resizeToHeight(1000); } } else { if ($image->getWidth() > 1000) { $image->resizeToWidth(1000); } } $image->save($fname); function getMIME($fname) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $fname); finfo_close($finfo); return $mime; } $filetype = explode('/', getMIME($fname)); $valid_formats = array("jpg", "png", "gif", "jpeg"); $this->validate($filetype[0] === 'image' and in_array($filetype[1], $valid_formats), $err, 'invalid image type'); if ($this->isValid()) { require_once $GLOBALS['dirpre'] . 'includes/S3/s3_config.php'; //Rename image name. $actual_image_name = time() . "." . $filetype[1]; if (isset($_GET['name']) && $_GET['name'] == 'bannerphoto') { $this->validate($image->getWidth() >= 1000, $err, 'Please upload a banner image at least 1000px wide.'); } $this->validate($s3->putObjectFile($fname, $bucket, $actual_image_name, S3::ACL_PUBLIC_READ), $err, 'upload failed'); if ($this->isValid()) { $reply = "https://{$bucket}.s3.amazonaws.com/{$actual_image_name}"; $this->success('image successfully uploaded'); $this->directrender('S3/S3', array('reply' => "up(\"{$reply}\");")); return; } } } } $this->error($err); $this->directrender('S3/S3'); }
public function downAppend($destPath) { $otherImage = new SimpleImage($destPath); $down = $otherImage->loadSourceIntoGD(); $source = $this->loadSourceIntoGD(); $product = imagecreatetruecolor($this->sourceImageWidth, $this->sourceImageHeight + $otherImage->getHeight()); imagecopy($product, $source, 0, 0, 0, 0, $this->sourceImageWidth, $this->sourceImageHeight); imagecopy($product, $down, 0, $this->sourceImageHeight, 0, 0, $otherImage->getWidth(), $otherImage->getHeight()); imagejpeg($product, $this->sourcePath, 90); imagedestroy($product); imagedestroy($source); imagedestroy($down); unset($otherImage); return true; }
/** * Returns array('success'=>true) or array('error'=>'error message') */ function handleUpload($uploadDirectory, $replaceOldFile = FALSE) { $folder = getcwd() . '/uploads/'; $thumbFolder = getcwd() . '/uploads/thumbs/'; if (!is_writable($uploadDirectory)) { return array('error' => "Server error. Upload directory isn't writable."); } if (!$this->file) { return array('error' => 'No files were uploaded.'); } $size = $this->file->getSize(); if ($size == 0) { return array('error' => 'File is empty'); } if ($size > $this->sizeLimit) { return array('error' => 'File is too large'); } $pathinfo = pathinfo($this->file->getName()); $filename = $pathinfo['filename']; //$filename = md5(uniqid()); $ext = $pathinfo['extension']; if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) { $these = implode(', ', $this->allowedExtensions); return array('error' => 'File has an invalid extension, it should be one of ' . $these . '.'); } if (!$replaceOldFile) { /// don't overwrite previous files that were uploaded while (file_exists($uploadDirectory . $filename . '.' . $ext)) { $filename .= rand(10, 99); } } if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) { $image = new SimpleImage(); $image->load($folder . $filename . '.' . $ext); $width = $image->getWidth(); $height = $image->getHeight(); $image->resize(150, 150); $image->save('uploads/thumbs/' . $filename . '-thumb.' . $ext); return array('success' => true, 'size' => $size, 'width' => $width, 'height' => $height, 'extension' => $ext, 'file_name' => $filename); } else { return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered'); } }
function main() { if (isset($_FILES['picturefile']['name'])) { $referersplit = preg_split("/[?]/", $_SERVER['HTTP_REFERER']); $referer = $referersplit[0]; try { if ($_FILES["picturefile"]["size"] > 5 * 1024 * 1024 || $_FILES['picturefile']['tmp_name'] == null) { throw new Exception('File too large!'); } else { if (getContentType($_FILES['picturefile']['name']) == null) { throw new Exception('File type not supported!'); } else { $filename = generateUniqueId() . "-" . $_FILES['picturefile']['name']; $tmpName = $_FILES['picturefile']['tmp_name']; $image = new SimpleImage(); $image->load($tmpName); $imageWasResized = false; if ($image->getHeight() > 1024) { $image->resizeToHeight(1024); } if ($image->getWidth() > 1024) { $image->resizeToWidth(1024); } $image->save($tmpName); // Saving even if not resized, to reduce compression level of file $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); fclose($fp); updateOrInsertImage($filename, $content); } } header('Location: ' . $referer . "?uploadresult=true&filelocation=php/io.php?file=" . $filename); return true; } catch (Exception $e) { header('Location: ' . $referer . "?uploadresult=false&errormsg=" . $e->getMessage()); return true; } } if (isset($_GET['id'])) { $slideshowId = $_GET['id']; $slideshowSrc = getSlideshow($slideshowId); $slideshow = array('id' => $slideshowId, 'src' => $slideshowSrc); sendJSONResponse(json_encode($slideshow)); return true; } if (isset($_POST['id'], $_POST['key'], $_POST['src'])) { $slideshowId = $_POST['id']; $slideshowKey = $_POST['key']; $slideshowToSave = $_POST['src']; if (isCorrectKey($slideshowId, $slideshowKey)) { updateSlideshow($slideshowId, $slideshowToSave); } else { throw new Exception("ERROR key is wrong"); } $result = array('id' => $slideshowId); sendJSONResponse(json_encode($result)); return true; } if (isset($_POST['create'])) { $id = generateUniqueId(); $key = generateRandomLegibleString(); createEmptySlideshow($id, $key); $idAndKey = array('id' => $id, 'key' => $key); sendJSONResponse(json_encode($idAndKey)); return true; } if (isset($_GET['file'])) { $imageId = $_GET['file']; $image = getImage($imageId); header("Content-type: " . getContentType($imageId)); print $image; return true; } return false; }
function check_size_and_rotation($pathname) { require_once mnminclude . "simpleimage.php"; $original = $pathname; $tmp = "{$pathname}.tmp"; $max_size = 2048; $image = new SimpleImage(); if ($image->rotate_exif($pathname)) { if ($image->save($tmp)) { $pathname = $tmp; clearstatcache(); } } if (filesize($pathname) > 1024 * 1024) { // Bigger than 1 MB if ($image->load($pathname) && ($image->getWidth() > $max_size || $image->getHeight() > $max_size)) { if ($image->getWidth() > $image->getHeight) { $image->resizeToWidth($max_size); } else { $image->resizeToHeight($max_size); } if ($image->save($tmp)) { $pathname = $tmp; clearstatcache(); } } } if ($pathname != $original && file_exists($pathname)) { if (!@rename($pathname, $original)) { syslog(LOG_INFO, "Error renaming file {$pathname} -> {$original}"); @unlink($pathname); } } $this->size = filesize($original); @chmod($original, 0777); return true; }
$Email = $row["email"]; $strFirstName = $row["first_name"]; $strLastName = $row["last_name"]; $strPhone = $row["cellphone"]; $intverification_id = $row["verification_id"]; } //make thumbnail if it is an image...? $strExtension = get_extension($strFileName); //name is filename of uploaded file if ($strExtension == "jpg" or $strExtension == "jpeg" or $strExtension == "png" or $strExtension = "gif") { //save thumbbail - [BUG] thumbnails are being rotated... ???? $imageThumbPath = PICTURETHUMBPATH . $strKeyLink . ".jpg"; $image = new SimpleImage(); //init object $image->load($uploaded_file); $width = $image->getWidth(); $height = $image->getHeight(); //$image->resize(100,100); //rescale $image->resizeToWidth(200); //we want to instead save it with proportions intact... $image->save(__ROOT__ . $imageThumbPath); } if ($strExtension == "pdf") { $strCopyExt = "pdf"; } else { $strCopyExt = "jpg"; } //send admin an email on upload if ($strFromPage == "receipts") { //get crypto rate $intCryptoRate = funct_Billing_GetRate();