-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUploadFileDisableThumbnailBehavior.php
More file actions
53 lines (47 loc) · 1.56 KB
/
UploadFileDisableThumbnailBehavior.php
File metadata and controls
53 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* UploadFileDesableThumbnailBehavior
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
/**
* Class UploadFileDesableThumbnailBehavior
*/
class UploadFileDisableThumbnailBehavior extends ModelBehavior {
/**
* beforeSave is called before a model is saved. Returning false from a beforeSave callback
* will abort the save operation.
*
* @param Model $model Model using this behavior
* @param array $options Options passed from Model::save().
* @return mixed False if the operation should abort. Any other result will continue.
* @see Model::save()
*/
public function beforeSave(Model $model, $options = array()) {
// phpunit用。Wysiwyg等のphpunitで'tmp_name'はセットされないため、tmp_nameが無いものはなにもしない。
if (!isset($model->data['UploadFile']['real_file_name']['tmp_name'])) {
return true;
}
// 画像以外だったらサムネイルを生成させない
$makeThumbnails = $this->_isImageFile(
$model->data['UploadFile']['real_file_name']['tmp_name']
);
$model->uploadSettings('real_file_name', 'thumbnails', $makeThumbnails);
return true;
}
/**
* MimeTypeをみてimageか判定する
*
* @param string $file ファイルへのパス
* @return bool
*/
protected function _isImageFile($file) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $file);
finfo_close($finfo);
$result = (substr($mimeType, 0, 5) === 'image');
return $result;
}
}