OSDN Git Service

Usersイメージファイルの容量チェックを追加
authorCake <cake_67@users.sourceforge.jp>
Thu, 18 Feb 2010 05:45:19 +0000 (14:45 +0900)
committerCake <cake_67@users.sourceforge.jp>
Thu, 18 Feb 2010 05:45:19 +0000 (14:45 +0900)
app/controllers/users_controller.php
app/plugins/media/models/attachment_ex.php

index 62e7870..4c30db0 100644 (file)
@@ -90,7 +90,26 @@ class UsersController extends ModuleController {
                                'checksum',
                                'group',
                                'alternative',
+                               'file',
                        );
+
+                       // validate
+                       // ファイル容量
+                       $filesize = Configure::read('Upload.imagefile.FileSizeMax');
+                       if (empty($filesize) || $filesize <= 0) {
+                               unset($this->User->Attachment->validate['file']['size']);
+                       } else {
+                               $this->User->Attachment->validate['file']['size']['rule'] = array('checkSize', $filesize.'K');
+                       }
+                       //ファイルサイズ
+                       $width = Configure::read('Upload.imagefile.WidthMax');
+                       $height = Configure::read('Upload.imagefile.HeightMax');
+                       if ((empty($width) || $width <= 0) || (empty($height) || $height <= 0)) {
+                               unset($this->User->Attachment->validate['file']['pixels']);
+                       } else {
+                               $this->User->Attachment->validate['file']['pixels']['rule'] = array('checkPixels', $width.'x'.$height);
+                       }
+
                        if ($this->User->saveAll($this->data, array(
                                'validate' => 'first',
                                'fieldList' => $fieldList
index 9c48ad2..f231d5f 100644 (file)
@@ -9,8 +9,17 @@ class AttachmentEx extends Attachment {
 
        function __construct($id = false, $table = null, $ds = null) {
 
+               // Uploadファイルの保存設定
                $this->actsAs['Media.Transfer']['destinationFile'] = ':Medium.short::DS::uuid:'.'.'.':Source.extension:';
 
+               // validate
+               $this->validate['file']['extension'] = array('rule' => array('checkExtension', false, array(
+                       'jpg', 'jpeg', 'png', 'gif',
+               )));
+               $this->validate['file']['notEmpty'] = array('rule' => array('checkMimeType', false, array(
+                       'image/jpeg', 'image/png', 'image/gif'
+               )));
+
                parent::__construct($id, $table, $ds);
        }