[17929] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[22206] | 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
[17929] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | /* アップロードファイル管理クラス */ |
---|
[22856] | 25 | class SC_UploadFile |
---|
[22567] | 26 | { |
---|
[23124] | 27 | public $temp_dir; |
---|
| 28 | public $save_dir; |
---|
[17929] | 29 | |
---|
[18379] | 30 | /** ファイルinputタグのname */ |
---|
[23124] | 31 | public $keyname = array(); |
---|
[18379] | 32 | |
---|
| 33 | /** 横サイズ */ |
---|
[23124] | 34 | public $width = array(); |
---|
[18379] | 35 | |
---|
| 36 | /** 縦サイズ */ |
---|
[23124] | 37 | public $height = array(); |
---|
[18379] | 38 | |
---|
| 39 | /** 指定する拡張子 */ |
---|
[23124] | 40 | public $arrExt = array(); |
---|
[18379] | 41 | |
---|
| 42 | /** 保存されたファイル名 */ |
---|
[23124] | 43 | public $temp_file = array(); |
---|
[18379] | 44 | |
---|
| 45 | /** DBから読み出したファイル名 */ |
---|
[23124] | 46 | public $save_file = array(); |
---|
[18379] | 47 | |
---|
| 48 | /** 項目名 */ |
---|
[23124] | 49 | public $disp_name = array(); |
---|
[18379] | 50 | |
---|
| 51 | /** 制限サイズ */ |
---|
[23124] | 52 | public $size = array(); |
---|
[18379] | 53 | |
---|
| 54 | /** 必須の場合:true */ |
---|
[23124] | 55 | public $necessary = array(); |
---|
[18379] | 56 | |
---|
| 57 | /** 画像の場合:true */ |
---|
[23124] | 58 | public $image = array(); |
---|
[18379] | 59 | |
---|
[17929] | 60 | // ファイル管理クラス |
---|
[23124] | 61 | public function __construct($temp_dir, $save_dir) |
---|
[22567] | 62 | { |
---|
[21755] | 63 | $this->temp_dir = rtrim($temp_dir, '/') . '/'; |
---|
| 64 | $this->save_dir = rtrim($save_dir, '/') . '/'; |
---|
[17929] | 65 | $this->file_max = 0; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | // ファイル情報追加 |
---|
[23124] | 69 | public function addFile($disp_name, $keyname, $arrExt, $size, $necessary=false, $width=0, $height=0, $image=true) |
---|
[22567] | 70 | { |
---|
[17929] | 71 | $this->disp_name[] = $disp_name; |
---|
| 72 | $this->keyname[] = $keyname; |
---|
| 73 | $this->width[] = $width; |
---|
| 74 | $this->height[] = $height; |
---|
| 75 | $this->arrExt[] = $arrExt; |
---|
| 76 | $this->size[] = $size; |
---|
| 77 | $this->necessary[] = $necessary; |
---|
| 78 | $this->image[] = $image; |
---|
| 79 | } |
---|
| 80 | // サムネイル画像の作成 |
---|
[23124] | 81 | public function makeThumb($src_file, $width, $height, $dst_file) |
---|
[22567] | 82 | { |
---|
[17929] | 83 | $objThumb = new gdthumb(); |
---|
| 84 | $ret = $objThumb->Main($src_file, $width, $height, $dst_file); |
---|
| 85 | |
---|
[21441] | 86 | if ($ret[0] != 1) { |
---|
[17929] | 87 | // エラーメッセージの表示 |
---|
[20538] | 88 | echo $ret[1]; |
---|
[17929] | 89 | exit; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | return basename($ret[1]); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | // アップロードされたファイルを保存する。 |
---|
[23124] | 96 | public function makeTempFile($keyname, $rename = IMAGE_RENAME) |
---|
[22567] | 97 | { |
---|
[20503] | 98 | $objErr = new SC_CheckError_Ex(); |
---|
[17929] | 99 | $cnt = 0; |
---|
| 100 | $arrKeyname = array_flip($this->keyname); |
---|
| 101 | |
---|
[23482] | 102 | if ($_FILES[$keyname]['error'] === UPLOAD_ERR_OK) { |
---|
[21441] | 103 | foreach ($this->keyname as $val) { |
---|
[17929] | 104 | // 一致したキーのファイルに情報を保存する。 |
---|
| 105 | if ($val == $keyname) { |
---|
| 106 | // 拡張子チェック |
---|
[21480] | 107 | $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->arrExt[$cnt]), array('FILE_EXT_CHECK')); |
---|
[17929] | 108 | // ファイルサイズチェック |
---|
[21480] | 109 | $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->size[$cnt]), array('FILE_SIZE_CHECK')); |
---|
[17929] | 110 | // エラーがない場合 |
---|
[21441] | 111 | if (!isset($objErr->arrErr[$keyname])) { |
---|
[17929] | 112 | // 画像ファイルの場合 |
---|
[21441] | 113 | if ($this->image[$cnt]) { |
---|
[17929] | 114 | // 保存用の画像名を取得する |
---|
| 115 | $dst_file = $this->lfGetTmpImageName($rename, $keyname); |
---|
| 116 | $this->temp_file[$cnt] = $this->makeThumb($_FILES[$keyname]['tmp_name'], $this->width[$cnt], $this->height[$cnt], $dst_file); |
---|
| 117 | // 画像ファイル以外の場合 |
---|
| 118 | } else { |
---|
| 119 | // 一意なファイル名を作成する。 |
---|
[21441] | 120 | if ($rename) { |
---|
[21515] | 121 | $uniqname = date('mdHi') . '_' . uniqid('').'.'; |
---|
[21755] | 122 | $this->temp_file[$cnt] = preg_replace("/^.*\./", $uniqname, $_FILES[$keyname]['name']); |
---|
[17929] | 123 | } else { |
---|
| 124 | $this->temp_file[$cnt] = $_FILES[$keyname]['name']; |
---|
| 125 | } |
---|
[20617] | 126 | if (move_uploaded_file($_FILES[$keyname]['tmp_name'], $this->temp_dir . $this->temp_file[$cnt])) { |
---|
[21514] | 127 | GC_Utils_Ex::gfPrintLog($_FILES[$keyname]['name'].' -> '. $this->temp_dir . $this->temp_file[$cnt]); |
---|
[20617] | 128 | } else { |
---|
[20863] | 129 | $objErr->arrErr[$keyname] = '※ ファイルのアップロードに失敗しました。<br />'; |
---|
[21515] | 130 | GC_Utils_Ex::gfPrintLog('File Upload Error!: ' . $_FILES[$keyname]['name'].' -> '. $this->temp_dir . $this->temp_file[$cnt]); |
---|
[20617] | 131 | } |
---|
[17929] | 132 | } |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | $cnt++; |
---|
| 136 | } |
---|
[23482] | 137 | } elseif ($_FILES[$keyname]['error'] === UPLOAD_ERR_NO_FILE) { |
---|
| 138 | $objErr->arrErr[$keyname] .= '※ ' |
---|
| 139 | . $this->disp_name[$arrKeyname[$keyname]] |
---|
| 140 | . 'が選択されていません。' |
---|
| 141 | . '<br />'; |
---|
| 142 | } else { |
---|
| 143 | $objErr->arrErr[$keyname] .= '※ ' |
---|
| 144 | . $this->disp_name[$arrKeyname[$keyname]] |
---|
| 145 | . 'のアップロードに失敗しました。' |
---|
| 146 | . 'エラーコードは[' . $_FILES[$keyname]['error'] . ']です。' |
---|
| 147 | . '<br />'; |
---|
[17929] | 148 | } |
---|
[22856] | 149 | |
---|
[17929] | 150 | return $objErr->arrErr[$keyname]; |
---|
| 151 | } |
---|
| 152 | |
---|
[18777] | 153 | // アップロードされたダウンロードファイルを保存する。 |
---|
[23124] | 154 | public function makeTempDownFile($keyname='down_file') |
---|
[22567] | 155 | { |
---|
[20503] | 156 | $objErr = new SC_CheckError_Ex(); |
---|
[18777] | 157 | $cnt = 0; |
---|
| 158 | $arrKeyname = array_flip($this->keyname); |
---|
[23483] | 159 | |
---|
| 160 | if ($_FILES[$keyname]['error'] === UPLOAD_ERR_OK) { |
---|
[21441] | 161 | foreach ($this->keyname as $val) { |
---|
[21527] | 162 | // 一致したキーのファイルに情報を保存する。 |
---|
[18819] | 163 | if ($val == $keyname) { |
---|
[18777] | 164 | // 拡張子チェック |
---|
[21480] | 165 | $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->arrExt[$cnt]), array('FILE_EXT_CHECK')); |
---|
[18777] | 166 | // ファイルサイズチェック |
---|
[21480] | 167 | $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->size[$cnt]), array('FILE_SIZE_CHECK')); |
---|
[18777] | 168 | // エラーがない場合 |
---|
[21527] | 169 | if (!isset($objErr->arrErr[$keyname])) { |
---|
[18777] | 170 | // 一意なファイル名を作成する。 |
---|
[21515] | 171 | $uniqname = date('mdHi') . '_' . uniqid('').'.'; |
---|
[21755] | 172 | $this->temp_file[$cnt] = preg_replace("/^.*\./", $uniqname, $_FILES[$keyname]['name']); |
---|
[18819] | 173 | $result = copy($_FILES[$keyname]['tmp_name'], $this->temp_dir . $this->temp_file[$cnt]); |
---|
[21514] | 174 | GC_Utils_Ex::gfPrintLog($result.' -> '. $this->temp_dir . $this->temp_file[$cnt]); |
---|
[22021] | 175 | SC_Utils_Ex::extendTimeOut(); |
---|
[18777] | 176 | } |
---|
| 177 | } |
---|
| 178 | $cnt++; |
---|
| 179 | } |
---|
[23483] | 180 | } elseif ($_FILES[$keyname]['error'] === UPLOAD_ERR_NO_FILE) { |
---|
| 181 | $objErr->arrErr[$keyname] = '※ ' |
---|
| 182 | . $this->disp_name[$arrKeyname[$keyname]] |
---|
| 183 | . 'が選択されていません。' |
---|
| 184 | . '<br />'; |
---|
| 185 | } elseif ($_FILES[$keyname]['error'] === UPLOAD_ERR_INI_SIZE) { |
---|
| 186 | $objErr->arrErr[$keyname] = '※ ' |
---|
| 187 | . $this->disp_name[$arrKeyname[$keyname]] |
---|
| 188 | . 'のアップロードに失敗しました。' |
---|
| 189 | . '(.htaccessファイルのphp_value upload_max_filesizeを調整してください)' |
---|
| 190 | . '<br />'; |
---|
| 191 | } else { |
---|
| 192 | $objErr->arrErr[$keyname] = '※ ' |
---|
| 193 | . $this->disp_name[$arrKeyname[$keyname]] |
---|
| 194 | . 'のアップロードに失敗しました。' |
---|
| 195 | . 'エラーコードは[' . $_FILES[$keyname]['error'] . ']です。' |
---|
| 196 | . '<br />'; |
---|
[18777] | 197 | } |
---|
[22856] | 198 | |
---|
[18819] | 199 | return $objErr->arrErr[$keyname]; |
---|
[18777] | 200 | } |
---|
| 201 | |
---|
[17929] | 202 | // 画像を削除する。 |
---|
[23124] | 203 | public function deleteFile($keyname) |
---|
[22567] | 204 | { |
---|
[20498] | 205 | $objImage = new SC_Image_Ex($this->temp_dir); |
---|
[17929] | 206 | $cnt = 0; |
---|
[21441] | 207 | foreach ($this->keyname as $val) { |
---|
[17929] | 208 | if ($val == $keyname) { |
---|
| 209 | // 一時ファイルの場合削除する。 |
---|
[21514] | 210 | if ($this->temp_file[$cnt] != '') { |
---|
[17929] | 211 | $objImage->deleteImage($this->temp_file[$cnt], $this->temp_dir); |
---|
| 212 | } |
---|
[21514] | 213 | $this->temp_file[$cnt] = ''; |
---|
| 214 | $this->save_file[$cnt] = ''; |
---|
[17929] | 215 | } |
---|
| 216 | $cnt++; |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
[18819] | 220 | // 画像を削除する。 |
---|
[23124] | 221 | public function deleteKikakuFile($keyname) |
---|
[22567] | 222 | { |
---|
[20498] | 223 | $objImage = new SC_Image_Ex($this->temp_dir); |
---|
[18819] | 224 | $cnt = 0; |
---|
[21441] | 225 | foreach ($this->keyname as $val) { |
---|
[18819] | 226 | if ($val == $keyname) { |
---|
| 227 | // 一時ファイルの場合削除する。 |
---|
[21514] | 228 | if ($this->temp_file[$cnt] != '') { |
---|
[18819] | 229 | $objImage->deleteImage($this->temp_file[$cnt], $this->temp_dir); |
---|
| 230 | } |
---|
[21514] | 231 | $this->temp_file[$cnt] = ''; |
---|
| 232 | //$this->save_file[$cnt] = ''; |
---|
[18819] | 233 | } |
---|
| 234 | $cnt++; |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | |
---|
[17929] | 238 | // 一時ファイルパスを取得する。 |
---|
[23124] | 239 | public function getTempFilePath($keyname) |
---|
[22567] | 240 | { |
---|
[17929] | 241 | $cnt = 0; |
---|
[21514] | 242 | $filepath = ''; |
---|
[21441] | 243 | foreach ($this->keyname as $val) { |
---|
[17929] | 244 | if ($val == $keyname) { |
---|
[21514] | 245 | if ($this->temp_file[$cnt] != '') { |
---|
[17929] | 246 | $filepath = $this->temp_dir . $this->temp_file[$cnt]; |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | $cnt++; |
---|
| 250 | } |
---|
[22856] | 251 | |
---|
[17929] | 252 | return $filepath; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | // 一時ファイルを保存ディレクトリに移す |
---|
[23124] | 256 | public function moveTempFile() |
---|
[22567] | 257 | { |
---|
[20498] | 258 | $objImage = new SC_Image_Ex($this->temp_dir); |
---|
[17929] | 259 | |
---|
[21926] | 260 | for ($cnt = 0; $cnt < count($this->keyname); $cnt++) { |
---|
[21514] | 261 | if (isset($this->temp_file[$cnt]) && $this->temp_file[$cnt] != '') { |
---|
[17929] | 262 | $objImage->moveTempImage($this->temp_file[$cnt], $this->save_dir); |
---|
| 263 | |
---|
| 264 | // すでに保存ファイルがあった場合は削除する。 |
---|
[21527] | 265 | if (isset($this->save_file[$cnt]) |
---|
| 266 | && $this->save_file[$cnt] != '' |
---|
[21755] | 267 | && !preg_match('|^sub/|', $this->save_file[$cnt]) |
---|
[21527] | 268 | ) { |
---|
[17929] | 269 | $objImage->deleteImage($this->save_file[$cnt], $this->save_dir); |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | |
---|
[18777] | 275 | // ダウンロード一時ファイルを保存ディレクトリに移す |
---|
[23124] | 276 | public function moveTempDownFile() |
---|
[22567] | 277 | { |
---|
[20498] | 278 | $objImage = new SC_Image_Ex($this->temp_dir); |
---|
[21926] | 279 | for ($cnt = 0; $cnt < count($this->keyname); $cnt++) { |
---|
[21514] | 280 | if (isset($this->temp_file[$cnt]) && $this->temp_file[$cnt] != '') { |
---|
[18777] | 281 | $objImage->moveTempImage($this->temp_file[$cnt], $this->save_dir); |
---|
| 282 | // すでに保存ファイルがあった場合は削除する。 |
---|
[21684] | 283 | if (isset($this->save_file[$cnt]) |
---|
[21514] | 284 | && $this->save_file[$cnt] != '' |
---|
[21755] | 285 | && !preg_match('|^sub/|', $this->save_file[$cnt]) |
---|
[21684] | 286 | ) { |
---|
[20562] | 287 | $objImage->deleteImage($this->save_file[$cnt], $this->save_dir); |
---|
[18777] | 288 | } |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | |
---|
[17929] | 293 | // HIDDEN用のファイル名配列を返す |
---|
[23124] | 294 | public function getHiddenFileList() |
---|
[22567] | 295 | { |
---|
[17929] | 296 | $cnt = 0; |
---|
| 297 | $arrRet = array(); |
---|
[21441] | 298 | foreach ($this->keyname as $val) { |
---|
| 299 | if (isset($this->temp_file[$cnt])) { |
---|
[21481] | 300 | $arrRet['temp_' . $val] = $this->temp_file[$cnt]; |
---|
[17929] | 301 | } |
---|
[21514] | 302 | if (isset($this->save_file[$cnt]) && $this->save_file[$cnt] != '') { |
---|
[21481] | 303 | $arrRet['save_' . $val] = $this->save_file[$cnt]; |
---|
[17929] | 304 | } |
---|
| 305 | $cnt++; |
---|
| 306 | } |
---|
[22856] | 307 | |
---|
[17929] | 308 | return $arrRet; |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | // HIDDENで送られてきたファイル名を取得する |
---|
[23124] | 312 | public function setHiddenFileList($arrPOST) |
---|
[22567] | 313 | { |
---|
[17929] | 314 | $cnt = 0; |
---|
[21441] | 315 | foreach ($this->keyname as $val) { |
---|
[21481] | 316 | $key = 'temp_' . $val; |
---|
[21441] | 317 | if (isset($arrPOST[$key]) && !empty($arrPOST[$key])) { |
---|
[17929] | 318 | $this->temp_file[$cnt] = $arrPOST[$key]; |
---|
| 319 | } |
---|
[21481] | 320 | $key = 'save_' . $val; |
---|
[21441] | 321 | if (isset($arrPOST[$key]) && !empty($arrPOST[$key])) { |
---|
[17929] | 322 | $this->save_file[$cnt] = $arrPOST[$key]; |
---|
| 323 | } |
---|
| 324 | $cnt++; |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | |
---|
[23124] | 328 | public function setHiddenKikakuFileList($arrPOST) |
---|
[22567] | 329 | { |
---|
[18819] | 330 | $cnt = 0; |
---|
[21441] | 331 | foreach ($this->keyname as $val) { |
---|
[21481] | 332 | $key = 'temp_' . $val; |
---|
[21441] | 333 | if (isset($arrPOST[$key])) { |
---|
[18819] | 334 | $this->temp_file[$cnt] = $arrPOST[$key]; |
---|
| 335 | } |
---|
[21481] | 336 | $key = 'save_' . $val; |
---|
[21441] | 337 | if (isset($arrPOST[$key]) && !empty($arrPOST[$key])) { |
---|
[18819] | 338 | $this->save_file[$cnt] = $arrPOST[$key]; |
---|
| 339 | } |
---|
| 340 | $cnt++; |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
[17929] | 344 | // フォームに渡す用のファイル情報配列を返す |
---|
[23124] | 345 | public function getFormFileList($temp_url, $save_url, $real_size = false) |
---|
[22567] | 346 | { |
---|
[17929] | 347 | $arrRet = array(); |
---|
| 348 | $cnt = 0; |
---|
[21441] | 349 | foreach ($this->keyname as $val) { |
---|
[21514] | 350 | if (isset($this->temp_file[$cnt]) && $this->temp_file[$cnt] != '') { |
---|
[21755] | 351 | // パスのスラッシュ/が連続しないようにする。 |
---|
| 352 | $arrRet[$val]['filepath'] = rtrim($temp_url, '/') . '/' . $this->temp_file[$cnt]; |
---|
| 353 | |
---|
[17929] | 354 | $arrRet[$val]['real_filepath'] = $this->temp_dir . $this->temp_file[$cnt]; |
---|
[21514] | 355 | } elseif (isset($this->save_file[$cnt]) && $this->save_file[$cnt] != '') { |
---|
[21755] | 356 | // パスのスラッシュ/が連続しないようにする。 |
---|
| 357 | $arrRet[$val]['filepath'] = rtrim($save_url, '/') . '/' . $this->save_file[$cnt]; |
---|
| 358 | |
---|
[17929] | 359 | $arrRet[$val]['real_filepath'] = $this->save_dir . $this->save_file[$cnt]; |
---|
| 360 | } |
---|
[21441] | 361 | if (isset($arrRet[$val]['filepath']) && !empty($arrRet[$val]['filepath'])) { |
---|
| 362 | if ($real_size) { |
---|
| 363 | if (is_file($arrRet[$val]['real_filepath'])) { |
---|
[17929] | 364 | list($width, $height) = getimagesize($arrRet[$val]['real_filepath']); |
---|
| 365 | } |
---|
| 366 | // ファイル横幅 |
---|
| 367 | $arrRet[$val]['width'] = $width; |
---|
| 368 | // ファイル縦幅 |
---|
| 369 | $arrRet[$val]['height'] = $height; |
---|
[21441] | 370 | } else { |
---|
[17929] | 371 | // ファイル横幅 |
---|
| 372 | $arrRet[$val]['width'] = $this->width[$cnt]; |
---|
| 373 | // ファイル縦幅 |
---|
| 374 | $arrRet[$val]['height'] = $this->height[$cnt]; |
---|
| 375 | } |
---|
| 376 | // 表示名 |
---|
| 377 | $arrRet[$val]['disp_name'] = $this->disp_name[$cnt]; |
---|
| 378 | } |
---|
| 379 | $cnt++; |
---|
| 380 | } |
---|
[22856] | 381 | |
---|
[17929] | 382 | return $arrRet; |
---|
| 383 | } |
---|
| 384 | |
---|
[18777] | 385 | // フォームに渡す用のダウンロードファイル情報を返す |
---|
[23124] | 386 | public function getFormDownFile() |
---|
[22567] | 387 | { |
---|
[21514] | 388 | $arrRet = ''; |
---|
[21926] | 389 | for ($cnt = 0; $cnt < count($this->keyname); $cnt++) { |
---|
[21514] | 390 | if (isset($this->temp_file[$cnt]) && $this->temp_file[$cnt] != '') { |
---|
[18777] | 391 | $arrRet = $this->temp_file[$cnt]; |
---|
[21514] | 392 | } elseif (isset($this->save_file[$cnt]) && $this->save_file[$cnt] != '') { |
---|
[18777] | 393 | $arrRet = $this->save_file[$cnt]; |
---|
| 394 | } |
---|
| 395 | } |
---|
[22856] | 396 | |
---|
[18777] | 397 | return $arrRet; |
---|
| 398 | } |
---|
[23124] | 399 | public function getFormKikakuDownFile() |
---|
[22567] | 400 | { |
---|
[20562] | 401 | $arrRet = array(); |
---|
[18819] | 402 | $cnt = 0; |
---|
[21441] | 403 | foreach ($this->keyname as $val) { |
---|
| 404 | if (isset($this->temp_file[$cnt])) { |
---|
[18819] | 405 | $arrRet[$val] = $this->temp_file[$cnt]; |
---|
[21514] | 406 | } elseif (isset($this->save_file[$cnt]) && $this->save_file[$cnt] != '') { |
---|
[18819] | 407 | $arrRet[$val] = $this->save_file[$cnt]; |
---|
| 408 | } |
---|
| 409 | $cnt++; |
---|
| 410 | } |
---|
[22856] | 411 | |
---|
[18819] | 412 | return $arrRet; |
---|
| 413 | } |
---|
[18777] | 414 | |
---|
[17929] | 415 | // DB保存用のファイル名配列を返す |
---|
[23124] | 416 | public function getDBFileList() |
---|
[22567] | 417 | { |
---|
[17929] | 418 | $cnt = 0; |
---|
[21926] | 419 | $dbFileList = array(); |
---|
[21441] | 420 | foreach ($this->keyname as $val) { |
---|
[21514] | 421 | if (isset($this->temp_file[$cnt]) && $this->temp_file[$cnt] != '') { |
---|
[21926] | 422 | $dbFileList[$val] = $this->temp_file[$cnt]; |
---|
[21441] | 423 | } else { |
---|
[21926] | 424 | $dbFileList[$val] = isset($this->save_file[$cnt]) ? $this->save_file[$cnt] : ''; |
---|
[17929] | 425 | } |
---|
| 426 | $cnt++; |
---|
| 427 | } |
---|
[22856] | 428 | |
---|
[21926] | 429 | return $dbFileList; |
---|
[17929] | 430 | } |
---|
| 431 | |
---|
| 432 | // DBで保存されたファイル名配列をセットする |
---|
[23124] | 433 | public function setDBFileList($arrVal) |
---|
[22567] | 434 | { |
---|
[17929] | 435 | $cnt = 0; |
---|
[21441] | 436 | foreach ($this->keyname as $val) { |
---|
[21514] | 437 | if (isset($arrVal[$val]) && $arrVal[$val] != '') { |
---|
[17929] | 438 | $this->save_file[$cnt] = $arrVal[$val]; |
---|
| 439 | } |
---|
| 440 | $cnt++; |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | |
---|
[18777] | 444 | // DBで保存されたダウンロードファイル名をセットする |
---|
[23124] | 445 | public function setDBDownFile($arrVal) |
---|
[22567] | 446 | { |
---|
[21515] | 447 | if (isset($arrVal['down_realfilename']) && $arrVal['down_realfilename'] != '') { |
---|
[18777] | 448 | $this->save_file[0] = $arrVal['down_realfilename']; |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | |
---|
[18819] | 452 | // DBで保存されたダウンロードファイル名をセットする(setDBDownFileと統合予定) |
---|
[23124] | 453 | public function setPostFileList($arrPost) |
---|
[22567] | 454 | { |
---|
[21926] | 455 | for ($cnt = 0;$cnt < count($this->keyname); $cnt++) { |
---|
[21441] | 456 | if (isset($arrPost['temp_down_realfilename:' . ($cnt+1)])) { |
---|
[18819] | 457 | $this->temp_file[$cnt] = $arrPost['temp_down_realfilename:' . ($cnt+1)]; |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | } |
---|
| 461 | |
---|
[17929] | 462 | // 画像をセットする |
---|
[23124] | 463 | public function setDBImageList($arrVal) |
---|
[22567] | 464 | { |
---|
[17929] | 465 | $cnt = 0; |
---|
[21441] | 466 | foreach ($this->keyname as $val) { |
---|
[21514] | 467 | if ($arrVal[$val] != '' && $val == 'tv_products_image') { |
---|
[17929] | 468 | $this->save_file[$cnt] = $arrVal[$val]; |
---|
| 469 | } |
---|
| 470 | $cnt++; |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | // DB上のファイルの内削除要求があったファイルを削除する。 |
---|
[23124] | 475 | public function deleteDBFile($arrVal) |
---|
[22567] | 476 | { |
---|
[20498] | 477 | $objImage = new SC_Image_Ex($this->temp_dir); |
---|
[17929] | 478 | $cnt = 0; |
---|
[21441] | 479 | foreach ($this->keyname as $val) { |
---|
[21514] | 480 | if ($arrVal[$val] != '') { |
---|
[21755] | 481 | if ($this->save_file[$cnt] == '' && !preg_match('|^sub/|', $arrVal[$val])) { |
---|
[17929] | 482 | $objImage->deleteImage($arrVal[$val], $this->save_dir); |
---|
| 483 | } |
---|
| 484 | } |
---|
| 485 | $cnt++; |
---|
| 486 | } |
---|
| 487 | } |
---|
| 488 | |
---|
[18777] | 489 | // DB上のダウンロードファイルの内削除要求があったファイルを削除する。 |
---|
[23124] | 490 | public function deleteDBDownFile($arrVal) |
---|
[22567] | 491 | { |
---|
[20498] | 492 | $objImage = new SC_Image_Ex($this->temp_dir); |
---|
[18777] | 493 | $cnt = 0; |
---|
[21514] | 494 | if ($arrVal['down_realfilename'] != '') { |
---|
[21755] | 495 | if ($this->save_file[$cnt] == '' && !preg_match('|^sub/|', $arrVal['down_realfilename'])) { |
---|
[18777] | 496 | $objImage->deleteImage($arrVal['down_realfilename'], $this->save_dir); |
---|
| 497 | } |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | |
---|
[17929] | 501 | // 必須判定 |
---|
[23124] | 502 | public function checkExists($keyname = '') |
---|
[22567] | 503 | { |
---|
[17929] | 504 | $cnt = 0; |
---|
| 505 | $arrRet = array(); |
---|
[21441] | 506 | foreach ($this->keyname as $val) { |
---|
[21514] | 507 | if ($val == $keyname || $keyname == '') { |
---|
[17929] | 508 | // 必須であればエラーチェック |
---|
| 509 | if ($this->necessary[$cnt] == true) { |
---|
[21514] | 510 | if (!isset($this->save_file[$cnt])) $this->save_file[$cnt] = ''; |
---|
| 511 | if (!isset($this->temp_file[$cnt])) $this->temp_file[$cnt] = ''; |
---|
[21684] | 512 | if ($this->save_file[$cnt] == '' |
---|
[23328] | 513 | && $this->temp_file[$cnt] == '' |
---|
| 514 | ) { |
---|
[21514] | 515 | $arrRet[$val] = '※ ' . $this->disp_name[$cnt] . 'がアップロードされていません。<br>'; |
---|
[17929] | 516 | } |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | $cnt++; |
---|
| 520 | } |
---|
[22856] | 521 | |
---|
[17929] | 522 | return $arrRet; |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | // 拡大率を指定して画像保存 |
---|
[23124] | 526 | public function saveResizeImage($keyname, $to_w, $to_h) |
---|
[22567] | 527 | { |
---|
[21514] | 528 | $path = ''; |
---|
[17929] | 529 | |
---|
| 530 | // keynameの添付ファイルを取得 |
---|
| 531 | $arrImageKey = array_flip($this->keyname); |
---|
| 532 | $file = $this->temp_file[$arrImageKey[$keyname]]; |
---|
| 533 | $filepath = $this->temp_dir . $file; |
---|
| 534 | |
---|
| 535 | $path = $this->makeThumb($filepath, $to_w, $to_h); |
---|
| 536 | |
---|
| 537 | // ファイル名だけ返す |
---|
| 538 | return basename($path); |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | /** |
---|
| 542 | * 一時保存用のファイル名を生成する |
---|
| 543 | * |
---|
[23124] | 544 | * @param string $rename |
---|
| 545 | * @param int $keyname |
---|
[18412] | 546 | * @return string |
---|
[17929] | 547 | */ |
---|
[23124] | 548 | public function lfGetTmpImageName($rename, $keyname = '', $uploadfile = '') |
---|
[22567] | 549 | { |
---|
[21442] | 550 | if ($rename === true) { |
---|
[17929] | 551 | // 一意なIDを取得し、画像名をリネームし保存 |
---|
[21515] | 552 | $uniqname = date('mdHi') . '_' . uniqid(''); |
---|
[17929] | 553 | } else { |
---|
| 554 | // アップロードした画像名で保存 |
---|
[18171] | 555 | $uploadfile = strlen($uploadfile) > 0 ? $uploadfile : $_FILES[$keyname]['name']; |
---|
| 556 | $uniqname = preg_replace('/(.+)\.(.+?)$/','$1', $uploadfile); |
---|
[17929] | 557 | } |
---|
| 558 | $dst_file = $this->temp_dir . $uniqname; |
---|
[22856] | 559 | |
---|
[17929] | 560 | return $dst_file; |
---|
| 561 | } |
---|
| 562 | } |
---|