当前位置: 首页>>代码示例>>PHP>>正文


PHP Image::getType方法代码示例

本文整理汇总了PHP中Image::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::getType方法的具体用法?PHP Image::getType怎么用?PHP Image::getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image::getType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: placeOver

 public function placeOver(Image $background, $posX, $posY)
 {
     $background->open();
     $this->open();
     imagecopy($background->getResource(), $this->getResource(), $posX, $posY, 0, 0, $this->getWidth(), $this->getHeight());
     $filepath = $background->getFilepath();
     return $this->_writeImageToDisk($filepath, $background->getResource(), $background->getType());
 }
开发者ID:mswagencia,项目名称:image,代码行数:8,代码来源:Image.php

示例2: add

 /**
  * file agregator
  *
  * adds a file to an ad
  *
  * @param   mixed   $file
  * @param   mixed   $target     a blank parameter in which the
  *                              target file witll be written
  * @access  public
  * @return  Boolean
  */
 public function add($file, &$target)
 {
     $target = $this->_generateFilename($file);
     $up_pic = self::target($target);
     $up_thm = self::target($target, true);
     $stored = $this->uploaded_and_stored($file, $up_pic);
     // do not create thumbnails if file is not supported (pdf)
     if (Image::isValidType(Image::getType($up_pic))) {
         Image::thumbnail($up_pic, $up_thm, 333);
     }
     return !Image::isError() && $stored;
 }
开发者ID:jimiyash,项目名称:cake-pluggables,代码行数:23,代码来源:upload.php

示例3: upload

 /**
  * Upload Image from POST
  * 
  * @param array $file - Part of $_FILES like $_FILES['photo']
  * @param string $fileName - Put image with this filename
  * @param Config $imageUploaderConfig
  * @throws RuntimeException
  * @throws InvalidArgumentException
  * @throws ImageException
  * @throws ImageUploaderException
  * @return Image
  */
 public static function upload($file, $fileName = null, Config $imageUploaderConfig = null)
 {
     $imageUploaderConfig = ConfigManager::mergeConfigs($imageUploaderConfig, ConfigManager::getConfig("Image", "ImageUploader")->AuxConfig);
     $uploadDir = $imageUploaderConfig->uploadDir;
     if (empty($uploadDir)) {
         throw new RuntimeException("Unable to get any appropriate uploadDir!");
     }
     if (!file_exists($uploadDir)) {
         throw new InvalidArgumentException("Upload directory {$uploadDir} doesn't exists.");
     }
     ensurePathLastSlash($uploadDir);
     if (!in_array($file["type"], $imageUploaderConfig->acceptedMimeTypes->toArray())) {
         throw new ImageException("Unsupported file uploaded!");
     }
     // Check if we have enough memory to open this file as image
     $info = getimagesize($file['tmp_name']);
     if ($info != false && !Image::checkMemAvailbleForResize($info[0], $info[1])) {
         throw new ImageUploaderException("Not enough memory to open image", static::EXCEPTION_IMAGE_IS_BIG);
     }
     // Check if we are able to create image resource from this file.
     $image = new Image($file['tmp_name']);
     $format = null;
     if (isset($imageUploaderConfig->saveFormat) and $imageUploaderConfig->saveFormat != null) {
         $format = $imageUploaderConfig->saveFormat;
     } else {
         $format = $image->getType();
     }
     if ($fileName === null) {
         $fileName = static::findNewFileName($uploadDir, $format);
     }
     $savePath = $uploadDir . $fileName;
     if (isset($imageUploaderConfig->minimumSize)) {
         $checkResult = $image->isSizeMeetRequirements($imageUploaderConfig->minimumSize->largeSideMinSize, $imageUploaderConfig->minimumSize->smallSideMinSize);
         if (!$checkResult) {
             throw new ImageUploaderException("Given image is smaller than specified minimum size.", static::EXCEPTION_IMAGE_IS_SMALL);
         }
     }
     switch ($format) {
         case Image::IMAGE_TYPE_JPEG:
             $image->writeJpeg($savePath);
             break;
         case Image::IMAGE_TYPE_PNG:
             $image->writePng($savePath);
             break;
         case Image::IMAGE_TYPE_GIF:
             $image->writeGif($savePath);
             break;
     }
     return $image;
 }
开发者ID:Welvin,项目名称:stingle,代码行数:62,代码来源:ImageUploader.class.php

示例4: generateImageCache

 /**
  * Generate image cache and return resulting path
  * 
  * @param string $folderName
  * @param Image $image
  * @param boolean $forceGenerate
  * @throws InvalidArgumentException
  * @throws RuntimeException
  * @return string
  */
 public function generateImageCache($folderName, Image $image, $forceGenerate = false)
 {
     if (!in_array($folderName, $this->config->folders->toArray())) {
         throw new InvalidArgumentException("There is no such folder defined with name {$folderName}!");
     }
     if (!file_exists($this->config->cacheDir . $folderName)) {
         throw new RuntimeException("There is no such folder {$folderName} in cache directory!");
     }
     $resultingFilePath = $this->config->cacheDir . $folderName . "/" . $image->fileName;
     if ($forceGenerate or !file_exists($resultingFilePath)) {
         switch ($image->getType()) {
             case Image::IMAGE_TYPE_JPEG:
                 $image->writeJpeg($resultingFilePath);
                 break;
             case Image::IMAGE_TYPE_GIF:
                 $image->writeGif($resultingFilePath);
                 break;
             case Image::IMAGE_TYPE_PNG:
                 $image->writePng($resultingFilePath);
                 break;
         }
     }
     return $resultingFilePath;
 }
开发者ID:Welvin,项目名称:stingle,代码行数:34,代码来源:ImageCache.class.php

示例5: add

 /**
  * Add a group
  */
 public function add($params)
 {
     $this->setView('add.php');
     $this->setTitle(__('GROUP_ADD_TITLE'));
     $is_logged = isset(User_Model::$auth_data);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     // Authorization
     if (!$is_admin) {
         throw new ActionException('Page', 'error404');
     }
     $group = array();
     // Saving data
     if (isset($_POST['name']) && isset($_POST['creation_date']) && isset($_POST['mail']) && isset($_POST['description'])) {
         $uploaded_files = array();
         try {
             // Members
             $members = array();
             if (isset($_POST['members_ids']) && is_array($_POST['members_ids'])) {
                 foreach ($_POST['members_ids'] as $id) {
                     if (ctype_digit($id)) {
                         $id = (int) $id;
                         $members[$id] = array('title' => isset($_POST['member_title_' . $id]) ? $_POST['member_title_' . $id] : '', 'admin' => isset($_POST['member_admin_' . $id]));
                     }
                 }
             }
             // Other info
             $data = array('name' => $_POST['name'], 'creation_date' => $_POST['creation_date'], 'mail' => $_POST['mail'], 'description' => $_POST['description'], 'members' => $members);
             // Avatar
             if (isset($_FILES['avatar']) && !is_array($_FILES['avatar']['name'])) {
                 if ($_FILES['avatar']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) {
                     throw new FormException('avatar');
                 }
                 if ($avatarpath = File::upload('avatar')) {
                     $uploaded_files[] = $avatarpath;
                     try {
                         $img = new Image();
                         $img->load($avatarpath);
                         $type = $img->getType();
                         if ($type == IMAGETYPE_JPEG) {
                             $ext = 'jpg';
                         } else {
                             if ($type == IMAGETYPE_GIF) {
                                 $ext = 'gif';
                             } else {
                                 if ($type == IMAGETYPE_PNG) {
                                     $ext = 'png';
                                 } else {
                                     throw new Exception();
                                 }
                             }
                         }
                         if ($img->getWidth() > 800) {
                             $img->setWidth(800, true);
                         }
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarpath);
                         // Thumb
                         $avatarthumbpath = $avatarpath . '.thumb';
                         $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarthumbpath);
                         unset($img);
                         $uploaded_files[] = $avatarthumbpath;
                         $data['avatar_path'] = $avatarthumbpath;
                         $data['avatar_big_path'] = $avatarpath;
                     } catch (Exception $e) {
                         throw new FormException('avatar');
                     }
                 }
             }
             $url_name = $this->model->create($data);
             Routes::redirect('group', array('group' => $url_name));
         } catch (FormException $e) {
             foreach ($uploaded_files as $uploaded_file) {
                 File::delete($uploaded_file);
             }
             foreach ($data as $key => $value) {
                 $group[$key] = $value;
             }
             $group['members'] = Student_Model::getInfoByUsersIds(array_keys($members));
             foreach ($group['members'] as &$member) {
                 if (isset($members[(int) $member['user_id']])) {
                     $member['title'] = $members[(int) $member['user_id']]['title'];
                     $member['admin'] = $members[(int) $member['user_id']]['admin'] ? '1' : '0';
                 }
             }
             $this->set('form_error', $e->getError());
         }
     }
     $this->set('group', $group);
     $this->addJSCode('Group.initEdit();');
 }
开发者ID:Godefroy,项目名称:iseplive,代码行数:95,代码来源:Group.php

示例6: iframe_add

    /**
     * Add a post
     */
    public function iframe_add()
    {
        $this->setView('iframe_add.php');
        @set_time_limit(0);
        $uploaded_files = array();
        try {
            if (!isset(User_Model::$auth_data)) {
                throw new Exception(__('POST_ADD_ERROR_SESSION_EXPIRED'));
            }
            $is_student = isset(User_Model::$auth_data['student_number']);
            // Message
            $message = isset($_POST['message']) ? trim($_POST['message']) : '';
            if ($message == '' || $message == __('PUBLISH_DEFAULT_MESSAGE')) {
                throw new Exception(__('POST_ADD_ERROR_NO_MESSAGE'));
            }
            $message = preg_replace('#\\n{2,}#', "\n\n", $message);
            // Category
            if (!isset($_POST['category']) || !ctype_digit($_POST['category'])) {
                throw new Exception(__('POST_ADD_ERROR_NO_CATEGORY'));
            }
            $category = (int) $_POST['category'];
            // Official post (in a group)
            $official = isset($_POST['official']);
            // Group
            $group = isset($_POST['group']) && ctype_digit($_POST['group']) ? (int) $_POST['group'] : 0;
            if ($group == 0) {
                $group = null;
                $official = false;
            } else {
                $groups_auth = Group_Model::getAuth();
                if (isset($groups_auth[$group])) {
                    if ($official && !$groups_auth[$group]['admin']) {
                        throw new Exception(__('POST_ADD_ERROR_OFFICIAL'));
                    }
                } else {
                    throw new Exception(__('POST_ADD_ERROR_GROUP_NOT_FOUND'));
                }
            }
            // Private message
            $private = isset($_POST['private']);
            if ($private && !$is_student) {
                throw new Exception(__('POST_ADD_ERROR_PRIVATE'));
            }
            $attachments = array();
            // Photos
            if (isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) {
                foreach ($_FILES['attachment_photo']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
                        throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
                    }
                }
                if ($filepaths = File::upload('attachment_photo')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : '';
                        try {
                            $img = new Image();
                            $img->load($filepath);
                            $type = $img->getType();
                            if ($type == IMAGETYPE_JPEG) {
                                $ext = 'jpg';
                            } else {
                                if ($type == IMAGETYPE_GIF) {
                                    $ext = 'gif';
                                } else {
                                    if ($type == IMAGETYPE_PNG) {
                                        $ext = 'png';
                                    } else {
                                        throw new Exception();
                                    }
                                }
                            }
                            if ($img->getWidth() > 800) {
                                $img->setWidth(800, true);
                            }
                            $img->save($filepath);
                            // Thumb
                            $thumbpath = $filepath . '.thumb';
                            $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            unset($img);
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $thumbpath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT'));
                        }
                    }
                }
            }
            // Vidéos
            /* @uses PHPVideoToolkit : http://code.google.com/p/phpvideotoolkit/
             * @requires ffmpeg, php5-ffmpeg
             */
            if (isset($_FILES['attachment_video']) && is_array($_FILES['attachment_video']['name'])) {
//.........这里部分代码省略.........
开发者ID:Godefroy,项目名称:iseplive,代码行数:101,代码来源:Post.php

示例7: createAndUploadImageDimensionMap

 private function createAndUploadImageDimensionMap(Image $image, $dimensionsKeyname)
 {
     $imd = $this->getDimensionByKeyname($dimensionsKeyname);
     $srcPth = $this->imagesRoot . $image->FilePath;
     if (file_exists($srcPth)) {
         $tempPath = tempnam(sys_get_temp_dir(), 'img_');
         if ($dimensionsKeyname == 'original') {
             $s3Path = $srcPth;
             $pts = getimagesize($s3Path);
             $width = $pts[0];
             $height = $pts[1];
             $newDims = array('x' => $width, 'y' => $height);
             $s3Path = $srcPth;
         } else {
             //need to redimension this image, using MagickWand
             $magick_wand = NewMagickWand();
             MagickReadImage($magick_wand, $srcPth);
             $width = MagickGetImageWidth($magick_wand);
             $height = MagickGetImageHeight($magick_wand);
             $newDims = $this->getNewDimensionsPreservingAspectRatio($width, $height, $imd->Width, $imd->Height);
             MagickScaleImage($magick_wand, $newDims['x'], $newDims['y']);
             MagickWriteImage($magick_wand, $tempPath);
             $s3Path = $tempPath;
         }
         $headers = array();
         //This holds the http headers for our S3 object.
         switch ($image->ImageType) {
             case 'GIF':
                 $headers['Content-Type'] = 'image/gif';
                 break;
             case 'JPG':
                 $headers['Content-Type'] = 'image/jpeg';
                 break;
             case 'PNG':
                 $headers['Content-Type'] = 'image/png';
                 break;
             default:
                 throw new Exception("Unrecognized type {$image->getType()}");
                 break;
         }
         //A "Far Future" expiration - maximizing the chance that the user's web browser will use
         //a cached version rather than requesting the file from Cloudfront.
         //Also set to public (as recommended by Google Speed Tracer), so that caching will work when
         //using SSL as well.  Even though Cloudfont doesn't support ssl today, someday it will
         //and we will be prepared!
         $headers['Cache-Control'] = 'public, max-age=315360000';
         //10 years
         $imDimMap = new ImageDimensionsMap();
         $imDimMap->ImageId = $image->Id;
         $imDimMap->ImageDimensionsId = $imd->Id;
         $imDimMap->Width = $newDims['x'];
         $imDimMap->Height = $newDims['y'];
         $imDimMap->Version = $image->Version;
         $imDimMap->save();
         //upload the new file to S3
         try {
             $acl = S3Service::ACL_PUBLIC_READ;
             if (!file_exists($tempPath)) {
                 throw new Exception("{$tempPath} dosn't exist");
             }
             $res = $this->s3->putObject(S3Service::inputFile($s3Path, true), $this->bucket, $this->getPath($image, $imDimMap, $imd), $acl, array(), $headers);
             if ($res) {
                 unlink($tempPath);
             } else {
                 //something's wrong.  Fail silently and just leave the old version if it exists.
                 //Don't throw an exception or raise a failure, because there's a user on the other side
                 //of this request waiting to see this image.
                 $imDimMap->Version = $imDimMap->Version - 1;
                 $imDimMap->save();
             }
         } catch (Exception $e) {
             //something's wrong.  Fail silently and just leave the old version if it exist.
             //Don't throw an exception or raise a failure, because there's a user on the other side
             //of this request waiting to see this image.
             $imDimMap->Version = $imDimMap->Version - 1;
             $imDimMap->save();
         }
     }
     return $imDimMap;
 }
开发者ID:awsninja,项目名称:awsninja_cloudfrontimageservice,代码行数:80,代码来源:CloudfrontImageService.php

示例8: edit

 /**
  * Edit a user
  */
 public function edit($params)
 {
     $this->setView('edit.php');
     $is_logged = isset(User_Model::$auth_data);
     $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
     // Authorization
     if (!$is_admin) {
         throw new ActionException('Page', 'error404');
     }
     try {
         $student = $this->model->getInfo($params['username']);
     } catch (Exception $e) {
         throw new ActionException('Page', 'error404');
     }
     $this->setTitle(__('STUDENT_EDIT_TITLE', array('username' => $student['username'])));
     // Birthday
     $student['birthday'] = date(__('USER_EDIT_FORM_BIRTHDAY_FORMAT'), strtotime($student['birthday']));
     // Saving data
     if (isset($_POST['mail']) && isset($_POST['msn']) && isset($_POST['jabber']) && isset($_POST['address']) && isset($_POST['zipcode']) && isset($_POST['city']) && isset($_POST['cellphone']) && isset($_POST['phone']) && isset($_POST['birthday']) && isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['student_number']) && isset($_POST['promo'])) {
         $uploaded_files = array();
         try {
             // Other info
             $user_data = array('mail' => $_POST['mail'], 'msn' => $_POST['msn'], 'jabber' => $_POST['jabber'], 'address' => $_POST['address'], 'zipcode' => $_POST['zipcode'], 'city' => $_POST['city'], 'cellphone' => $_POST['cellphone'], 'phone' => $_POST['phone'], 'birthday' => $_POST['birthday']);
             $student_data = array('firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'student_number' => $_POST['student_number'], 'promo' => $_POST['promo'], 'cesure' => isset($_POST['cesure']));
             // Avatar
             if (isset($_FILES['avatar']) && !is_array($_FILES['avatar']['name'])) {
                 if ($_FILES['avatar']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) {
                     throw new FormException('avatar');
                 }
                 if ($avatarpath = File::upload('avatar')) {
                     $uploaded_files[] = $avatarpath;
                     try {
                         $img = new Image();
                         $img->load($avatarpath);
                         $type = $img->getType();
                         if ($type == IMAGETYPE_JPEG) {
                             $ext = 'jpg';
                         } else {
                             if ($type == IMAGETYPE_GIF) {
                                 $ext = 'gif';
                             } else {
                                 if ($type == IMAGETYPE_PNG) {
                                     $ext = 'png';
                                 } else {
                                     throw new Exception();
                                 }
                             }
                         }
                         if ($img->getWidth() > 800) {
                             $img->setWidth(800, true);
                         }
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarpath);
                         // Thumb
                         $avatarthumbpath = $avatarpath . '.thumb';
                         $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
                         $img->setType(IMAGETYPE_JPEG);
                         $img->save($avatarthumbpath);
                         unset($img);
                         $uploaded_files[] = $avatarthumbpath;
                         $student_data['avatar_path'] = $avatarthumbpath;
                         $student_data['avatar_big_path'] = $avatarpath;
                     } catch (Exception $e) {
                         throw new FormException('avatar');
                     }
                 }
             }
             $user_model = new User_Model();
             $user_model->save((int) $student['id'], $user_data);
             $this->model->save($student['username'], $student_data);
             Routes::redirect('student', array('username' => $params['username']));
         } catch (FormException $e) {
             foreach ($uploaded_files as $uploaded_file) {
                 File::delete($uploaded_file);
             }
             foreach ($student_data as $key => $value) {
                 $student[$key] = $value;
             }
             foreach ($user_data as $key => $value) {
                 $student[$key] = $value;
             }
             $this->set('form_error', $e->getError());
         }
     }
     $this->set('student', $student);
     $this->addJSCode('User.initEdit();');
 }
开发者ID:Godefroy,项目名称:iseplive,代码行数:90,代码来源:Student.php

示例9: Image

<?php

include '../class.Images.php';
//There’s so much to know about an image. Go get some information!
$image = new Image('../test/image3.jpg');
print 'Width: ' . $image->getWidth() . '<br />';
print 'Height: ' . $image->getHeight() . '<br />';
print 'Extension: ' . $image->getExtension() . '<br />';
print 'Mime: ' . $image->getMimeType() . '<br />';
print 'Type: ' . $image->getType() . '<br />';
print 'Filesize in Bytes: ' . $image->getFileSizeInBytes() . '<br />';
print 'Filesize in kBytes: ' . $image->getFileSizeInKiloBytes() . '<br />';
print 'Filesize readable: ' . $image->getFileSize() . '<br />';
print 'Ratio Width:Height: ' . $image->getRatioWidthToHeight() . '<br />';
print 'Ratio Height:Width: ' . $image->getRatioHeightToWidth() . '<br />';
print 'Is it RGB?: ' . $image->isRGB();
开发者ID:hd132624,项目名称:class.Images.php,代码行数:16,代码来源:example6.php

示例10: index


//.........这里部分代码省略.........
                     }
                     if (isset($liste[7])) {
                         $city = $liste[7];
                     }
                     if (isset($liste[8])) {
                         $cellphone = $liste[8];
                     }
                     if (isset($liste[9])) {
                         $phone = $liste[9];
                     }
                     if (isset($liste[10])) {
                         $birthday = $liste[10];
                     }
                     if (!$this->model->checkuser($username, 1)) {
                         $this->model->insertUsers(trim($username), trim($admin), trim($mail), trim($msn), trim($jabber), trim($address), trim($zipcode), trim($city), trim($cellphone), trim($phone), trim($birthday));
                     }
                 }
             }
             fclose($fp);
             if (file_exists($path . 'students.csv')) {
                 $fp = fopen($path . 'students.csv', "r");
             } else {
                 throw new Exception(__('ADMIN_POST_CSVERROR2'));
             }
             $i = 0;
             while (!feof($fp)) {
                 $i = $i + 1;
                 // Tant qu'on n'atteint pas la fin du fichier
                 $ligne = fgets($fp, 4096);
                 /* On lit une ligne */
                 // On récupère les champs séparés par ; dans liste
                 $liste = explode(";", $ligne);
                 // On assigne les variables
                 if (strlen($liste[0]) > 1) {
                     if (isset($liste[0])) {
                         $username = $liste[0];
                     }
                     if (isset($liste[1])) {
                         $lastname = $liste[1];
                     }
                     if (isset($liste[2])) {
                         $firstname = $liste[2];
                     }
                     if (isset($liste[3])) {
                         $student_number = $liste[3];
                     }
                     if (isset($liste[4])) {
                         $promo = $liste[4];
                     }
                     if (isset($liste[5])) {
                         $cesure = $liste[5];
                     }
                     if (!$this->model->checkuser($username, 2)) {
                         $this->model->insertStudents(trim($username), trim($lastname), trim($firstname), trim($student_number), trim($promo), trim($cesure));
                     }
                     // On déplace et formate les photos dans le dossier avatars
                     $avatarpath = $path . 'photos_students/' . $student_number . '.jpg';
                     $img = new Image();
                     $img->load($avatarpath);
                     $type = $img->getType();
                     if ($type == IMAGETYPE_JPEG) {
                         $ext = 'jpg';
                     } else {
                         if ($type == IMAGETYPE_GIF) {
                             $ext = 'gif';
                         } else {
                             if ($type == IMAGETYPE_PNG) {
                                 $ext = 'png';
                             } else {
                                 throw new Exception();
                             }
                         }
                     }
                     if ($img->getWidth() > 800) {
                         $img->setWidth(800, true);
                     }
                     $img->setType(IMAGETYPE_JPEG);
                     $img->save($avatarpath);
                     // Thumb
                     $avatarthumbpath = $path . 'photos_students/' . $student_number . '_thumb.jpg';
                     $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
                     $img->setType(IMAGETYPE_JPEG);
                     $img->save($avatarthumbpath);
                     if (FILE::exists(DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/')) {
                         FILE::move($avatarthumbpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
                         FILE::move($avatarpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
                     } else {
                         FILE::makeDir(DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
                         FILE::move($avatarthumbpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
                         FILE::move($avatarpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
                     }
                     unset($img);
                 }
             }
             fclose($fp);
             // On supprime le tout du dossier temp
             FILE::delete($path);
         }
     }
 }
开发者ID:Godefroy,项目名称:iseplive,代码行数:101,代码来源:Administration.php

示例11: addAttachment

    public function addAttachment($param)
    {
        $this->setView('iframe_add.php');
        $is_logged = isset(User_Model::$auth_data);
        $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
        @set_time_limit(0);
        $uploaded_files = array();
        $attachments = array();
        try {
            if ($is_admin && isset($param['id']) && isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) {
                foreach ($_FILES['attachment_photo']['size'] as $size) {
                    if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
                        throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
                    }
                }
                if ($filepaths = File::upload('attachment_photo')) {
                    foreach ($filepaths as $filepath) {
                        $uploaded_files[] = $filepath;
                    }
                    foreach ($filepaths as $i => $filepath) {
                        $name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : '';
                        try {
                            $img = new Image();
                            $img->load($filepath);
                            $type = $img->getType();
                            if ($type == IMAGETYPE_JPEG) {
                                $ext = 'jpg';
                            } else {
                                if ($type == IMAGETYPE_GIF) {
                                    $ext = 'gif';
                                } else {
                                    if ($type == IMAGETYPE_PNG) {
                                        $ext = 'png';
                                    } else {
                                        throw new Exception();
                                    }
                                }
                            }
                            if ($img->getWidth() > 800) {
                                $img->setWidth(800, true);
                            }
                            $img->save($filepath);
                            // Thumb
                            $thumbpath = $filepath . '.thumb';
                            $img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]);
                            $img->setType(IMAGETYPE_JPEG);
                            $img->save($thumbpath);
                            unset($img);
                            $attachments[] = array($filepath, $name, $thumbpath);
                            $uploaded_files[] = $thumbpath;
                        } catch (Exception $e) {
                            throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT'));
                        }
                    }
                }
                // Attach files
                foreach ($attachments as $attachment) {
                    $this->model->attachFile($param['id'], $attachment[0], $attachment[1], isset($attachment[2]) ? $attachment[2] : null);
                }
                $this->addJSCode('
						parent.location = "' . Config::URL_ROOT . Routes::getPage('post', array('id' => $param['id'])) . '";
					');
            }
            Post_Model::clearCache();
        } catch (Exception $e) {
            // Delete all uploading files in tmp
            foreach ($uploaded_files as $uploaded_file) {
                File::delete($uploaded_file);
            }
            $this->addJSCode('
				with(parent){
					Post.errorForm(' . json_encode($e->getMessage()) . ');
				}
			');
        }
    }
开发者ID:ArnaudRib,项目名称:Site,代码行数:76,代码来源:Post.php

示例12: isepdorPage


//.........这里部分代码省略.........
            }
            for ($i = 0; $i < count($post); $i++) {
                if ($post[$i]['extra'] == 1) {
                    $post[$i]['extra'] = "soiree";
                } else {
                    $post[$i]['extra'] = NULL;
                }
                if ($post[$i]['id'] != "") {
                    $this->model->updateEvent($post[$i]['name'], $post[$i]['id'], $post[$i]['extra']);
                } elseif ($post[$i]['id'] == "") {
                    $this->model->insertEvent($post[$i]['name'], $post[$i]['extra']);
                }
            }
        }
        /*Code qui met à jour les date de vote des isep d'or
         *
         */
        if (isset($_POST['dates'])) {
            $post = json_decode($_POST['dates'], true);
            $this->model->insertDate($post[0][0], $post[0][1], $post[1][0], $post[1][1], $post[2][0], $post[2][1]);
        }
        /*
         * Change l'image diplome
         */
        if (isset($_FILES['diplome']) && !is_array($_FILES['diplome']['name'])) {
            if ($_FILES['diplome']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) {
                throw new FormException('size');
            }
            if ($avatarpath = File::upload('diplome')) {
                $uploaded_files[] = $avatarpath;
                try {
                    $img = new Image();
                    $img->load($avatarpath);
                    $type = $img->getType();
                    if ($type == IMAGETYPE_JPEG) {
                        $ext = 'jpg';
                    } else {
                        if ($type == IMAGETYPE_GIF) {
                            $ext = 'gif';
                        } else {
                            if ($type == IMAGETYPE_PNG) {
                                $ext = 'png';
                            } else {
                                throw new Exception();
                            }
                        }
                    }
                    if ($img->getHeight() != 794 || $img->getWidth() != 1122) {
                        throw new FormException('width');
                    }
                    $img->setType($type);
                    $img->save($avatarpath);
                    unset($img);
                    if (isset($avatarpath) && File::exists($avatarpath)) {
                        $avatar_path = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "diplomeIsepDOr9652.png";
                        $avatar_dir = File::getPath($avatar_path) . "/diplomeIsepDOr9652.png";
                        File::rename($avatarpath, $avatar_dir);
                    }
                } catch (FormException $e) {
                    $this->set('form_error', $e->getError());
                }
                foreach ($uploaded_files as $uploaded_file) {
                    File::delete($uploaded_file);
                }
            }
            Post_Model::clearCache();
开发者ID:hugonicolas,项目名称:Site,代码行数:67,代码来源:Administration.php


注:本文中的Image::getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。