public function avatarProcess() { $callbackId = PFunctions::hex2base64(sha1(__METHOD__)); if (PPostHandler::isHandling()) { if (!($User = APP_User::login())) { return false; } $vars =& PPostHandler::getVars(); if (!isset($_FILES['av'])) { return false; } if ($_FILES['av']['error'] != UPLOAD_ERR_OK) { return false; } $img = new MOD_images_Image($_FILES['av']['tmp_name']); if (!$img->isImage()) { return false; } $size = $img->getImageSize(); $type = $size[2]; // maybe this should be changed by configuration if ($type != IMAGETYPE_GIF && $type != IMAGETYPE_JPEG && $type != IMAGETYPE_PNG) { return false; } $newWidth = $size[0]; $newHeight = $size[1]; if ($newWidth > 100) { $newWidth = 100; } if ($newHeight > 100) { $newHeight = 100; } $img->createThumb($this->avatarDir->dirName(), $User->getId(), $newWidth, $newHeight, true); $img->createThumb($this->avatarDir->dirName(), $User->getId() . '_xs', 50, 50, true); return false; } else { PPostHandler::setCallback($callbackId, __CLASS__, __FUNCTION__); return $callbackId; } }
/** * processing image uploads * * @todo sizes should be customizable */ public function uploadProcess(&$vars) { // NEW CHECKS if (!($member = $this->getLoggedInMember())) { $vars['error'] = 'Gallery_NotLoggedIn'; return false; } if (!isset($_FILES['gallery-file']) || !is_array($_FILES['gallery-file']) || count($_FILES['gallery-file']) == 0) { $vars['error'] = 'Gallery_UploadError'; return false; } $noError = true; // flag for error on one file $userDir = new PDataDir('gallery/user' . $member->get_userid()); $insert = $this->dao->prepare(' INSERT INTO `gallery_items` (`id`, `user_id_foreign`, `file`, `original`, `flags`, `mimetype`, `width`, `height`, `title`, `created`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW()) '); $itemId = false; $insert->bindParam(0, $itemId); $userId = $member->get_userid(); $insert->bindParam(1, $userId); $hash = false; $insert->bindParam(2, $hash); $orig = false; $insert->bindParam(3, $orig); $flags = 0; $insert->bindParam(4, $flags); $mimetype = false; $insert->bindParam(5, $mimetype); $width = false; $insert->bindParam(6, $width); $height = false; $insert->bindParam(7, $height); $title = false; $insert->bindParam(8, $title); foreach ($_FILES['gallery-file']['error'] as $key => $error) { $fileName = $_FILES['gallery-file']['name'][$key]; // if upload failed, set error message if (!empty($fileName) && $error != UPLOAD_ERR_OK) { $noError = false; switch ($error) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $vars['fileErrors'][$fileName] = 'Gallery_UploadFileTooLarge'; break; default: $vars['fileErrors'][$fileName] = 'Gallery_UploadError'; break; } } elseif (!empty($fileName)) { // upload succeeded -> check if image $img = new MOD_images_Image($_FILES['gallery-file']['tmp_name'][$key]); if (!$img->isImage()) { $noError = false; $vars['fileErrors'][$fileName] = 'Gallery_UploadNotImage'; } else { // upload is image // resize $size = $img->getImageSize(); $original_x = min($size[0], PVars::getObj('images')->max_width); $original_y = min($size[1], PVars::getObj('images')->max_height); $tempDir = dirname($_FILES['gallery-file']['tmp_name'][$key]); $resizedName = md5($_FILES['gallery-file']['tmp_name'][$key]) . '_resized'; $img->createThumb($tempDir, $resizedName, $original_x, $original_y, true, 'ratio'); $tempFile = $tempDir . '/' . $resizedName; // create new image object from resized image $img = new MOD_images_Image($tempFile); $size = $img->getImageSize(); $type = $size[2]; $hash = $img->getHash(); if ($userDir->fileExists($hash)) { continue; } if (!$userDir->copyTo($tempFile, $hash)) { continue; } if (!($result = $this->createThumbnails($userDir, $img))) { return false; } $itemId = $this->dao->nextId('gallery_items'); $orig = $_FILES['gallery-file']['name'][$key]; $mimetype = image_type_to_mime_type($type); $width = $size[0]; $height = $size[1]; $title = $orig; try { $insert->execute(); } catch (PException $e) { error_log($e->__toString()); } if ($vars['galleryId']) { $this->dao->exec("INSERT INTO `gallery_items_to_gallery` SET `gallery_id_foreign` = '" . $vars['galleryId'] . "', `item_id_foreign`= " . $itemId); } $vars['fileErrors'][$_FILES['gallery-file']['name'][$key]] = 'Gallery_UploadFileSuccessfule'; unlink($tempFile); } } } return $noError; }
public function avatarMake($memberid, $img_file, $using_original = false) { $img = new MOD_images_Image($img_file); if (!$img->isImage()) { return false; } $size = $img->getImageSize(); $type = $size[2]; // maybe this should be changed by configuration if ($type != IMAGETYPE_GIF && $type != IMAGETYPE_JPEG && $type != IMAGETYPE_PNG) { return false; } $max_x = $size[0]; $max_y = $size[1]; if ($max_x > 150) { $max_x = 150; } if (!$using_original) { $original_x = min($size[0], PVars::getObj('images')->max_width); $original_y = min($size[1], PVars::getObj('images')->max_height); $this->writeMemberphoto($memberid); $img->createThumb($this->avatarDir->dirName(), $memberid . '_original', $original_x, $original_y, true, 'ratio'); } $img->createThumb($this->avatarDir->dirName(), $memberid, $max_x, $max_y, true, ''); $img->createThumb($this->avatarDir->dirName(), $memberid . '_200', 200, 266, true, 'ratio'); $img->createThumb($this->avatarDir->dirName(), $memberid . '_xs', 50, 50, true, 'square'); $img->createThumb($this->avatarDir->dirName(), $memberid . '_150', 150, 150, true, 'square'); $img->createThumb($this->avatarDir->dirName(), $memberid . '_30_30', 30, 30, true, 'square'); $img->createThumb($this->avatarDir->dirName(), $memberid . '_500', 500, 500, true, 'ratio'); return true; }
/** * takes care of a group image being uploaded * * @access private * @return mixed - false on fail or the name of the uploaded image */ private function handleImageUpload() { if ($_FILES['group_image']['error'] != 0) { return false; } else { $dir = new PDataDir('groups'); $img = new MOD_images_Image($_FILES['group_image']['tmp_name']); $new_name = $img->getHash(); if (empty($new_name)) { return false; } if (!($dir->fileExists($new_name) || $dir->copyTo($_FILES['group_image']['tmp_name'], $new_name))) { return false; } else { // yup, hackish way of resizing an image // feel free to add a resize function to MOD_images_Image and change this bit // or create an image entity with all needed functionality in ONE place // ... in my dreams ... $img->createThumb($dir->dirName(), $new_name, 300, 300, true); $img->createThumb($dir->dirName(), 'thumb', 100, 100); return $new_name; } } }