/** * 画像を保存する * * @param array $data * @return array */ public function saveImage($data) { // TODO インストール時にfilesの書き込み権限チェック&フォルダ作成 $saveDir = WWW_ROOT . 'files' . DS . 'theme_configs' . DS; $images = array('logo', 'main_image_1', 'main_image_2', 'main_image_3', 'main_image_4', 'main_image_5'); $thumbSuffix = '_thumb'; $old = $this->findExpanded(); foreach ($images as $image) { if (!empty($data['ThemeConfig'][$image]['tmp_name'])) { @unlink($saveDir . $old[$image]); $pathinfo = pathinfo($old[$image]); @unlink($saveDir . $pathinfo['filename'] . $thumbSuffix . $pathinfo['extension']); $fileName = $data['ThemeConfig'][$image]['name']; $ext = pathinfo($fileName, PATHINFO_EXTENSION); $filePath = $saveDir . $image . '.' . $ext; $thumbPath = $saveDir . $image . $thumbSuffix . '.' . $ext; move_uploaded_file($data['ThemeConfig'][$image]['tmp_name'], $filePath); $Imageresizer = new Imageresizer(); $Imageresizer->resize($filePath, $thumbPath, 320, 320); $data['ThemeConfig'][$image] = $image . '.' . $ext; } else { unset($data['ThemeConfig'][$image]); } } return $data; }
/** * セッションに保存した一時ファイルを出力する * @param string $name * @return void * @access public */ public function tmp() { $size = ''; $args = func_get_args(); if (func_num_args() > 1) { $size = $args[0]; $name = $args[1]; } else { $name = $args[0]; } $sessioName = str_replace(array('.', '/'), array('_', '_'), $name); $sessionData = $this->Session->read('Upload.' . $sessioName); Configure::write('debug', 0); $type = $sessionData['type']; $ext = decodeContent($type, $name); if (!$ext) { $this->notFound(); } $fileInfo = array(); if (isset($sessionData['imagecopy'][$size])) { $fileInfo = $sessionData['imagecopy'][$size]; } elseif (isset($sessionData['imageresize'])) { $fileInfo = $sessionData['imageresize']; } else { $size = ''; } if (!$size) { $data = $this->Session->read('Upload.' . $sessioName . '.data'); } else { if (is_dir(TMP . 'uploads')) { mkdir(TMP . 'uploads'); chmod(TMP . 'uploads', 0777); } $path = TMP . 'uploads' . DS . $name; $file = new File($path, true); $file->write($this->Session->read('Upload.' . $sessioName . '.data'), 'wb'); $file->close(); $thumb = false; if (!empty($fileInfo['thumb'])) { $thumb = $fileInfo['thumb']; } $imageresizer = new Imageresizer(APP . 'tmp'); $imageresizer->resize($path, $path, $fileInfo['width'], $fileInfo['height'], $thumb); $data = file_get_contents($path); unlink($path); } if ($ext != 'gif' && $ext != 'jpg' && $ext != 'png') { Header("Content-disposition: attachment; filename=" . $name); } Header("Content-type: " . $type . "; name=" . $name); echo $data; exit; }
/** * 画像を表示する * コアの画像等も表示可 * * @param int $width * @param int $height * @param array パス情報 * @return void * @access public */ public function admin_img_thumb() { $args = func_get_args(); $width = $args[0]; $height = $args[1]; unset($args[0]); unset($args[1]); $args = array_values($args); if ($width == 0) { $width = 100; } if ($height == 0) { $height = 100; } $args = $this->_parseArgs($args); $contents = array('jpeg' => 'jpeg', 'jpg' => 'jpeg', 'gif' => 'gif', 'png' => 'png'); extract($args); $pathinfo = pathinfo($fullpath); if (!isset($this->_tempalteTypes[$type]) || !isset($contents[$pathinfo['extension']]) || !file_exists($fullpath)) { $this->notFound(); } header("Content-type: image/" . $contents[$pathinfo['extension']]); $Imageresizer = new Imageresizer(); $Imageresizer->resize($fullpath, null, $width, $height); exit; }
/** * 画像ファイルをコピーする * リサイズ可能 * * @param Model $model * @param string コピー元のパス * @param string コピー先のパス * @param int 横幅 * @param int 高さ * @return boolean * @access public */ function resizeImage($source, $distination, $width = 0, $height = 0, $thumb = false) { if ($width > 0 || $height > 0) { $imageresizer = new Imageresizer(); $ret = $imageresizer->resize($source, $distination, $width, $height, $thumb); } else { $ret = copy($source, $distination); } if ($ret) { chmod($distination, 0666); } return $ret; }
/** * 画像ファイルをコピーする * リサイズ可能 * * @param Model $model * @param string コピー元のパス * @param string コピー先のパス * @param int 横幅 * @param int 高さ * @return boolean * @access public */ function resizeImage($source, $distination, $width = 0, $height = 0, $thumb = false) { if ($width > 0 || $height > 0) { App::import('Vendor', 'Imageresizer'); $imageresizer = new Imageresizer(APP . 'tmp'); $ret = $imageresizer->resize($source, $distination, $width, $height, $thumb); } else { $ret = copy($source, $distination); } if ($ret) { chmod($distination, 0666); } return $ret; }
/** * 画像を保存する。 * * @return bool * @access public */ public function saveMobilePostImg($data) { //保存先を指定する $saveDir = WWW_ROOT . 'files' . DS . 'mobile_post' . DS; //サムネイルにはプレフィックスをつける $thumbSuffix = 'thum_'; //アップロード画像の保存処理 if (!empty($data['MobilePost']['file']['tmp_name'])) { //現在のファイル名と、そこから拡張子を確認する。 $fileName = $data['MobilePost']['file']['name']; $ext = pathinfo($fileName, PATHINFO_EXTENSION); //新しいファイル名 $fileNamePrefix = 'mobile_post_img'; $fileNameNo = date("YmdHis"); $newFileName = $fileNamePrefix . $fileNameNo; $filePath = $saveDir . $newFileName . '.' . $ext; $thumbPath = $saveDir . $thumbSuffix . $newFileName . '.' . $ext; move_uploaded_file($data['MobilePost']['file']['tmp_name'], $filePath); //サムネイル生成 $Imageresizer = new Imageresizer(); $Imageresizer->resize($filePath, $thumbPath, 320, 320); $data['MobilePost']['file'] = $newFileName . '.' . $ext; } else { unset($data['MobilePost']['file']); } return $data; }