unload()CakePHP Uploader插件似乎不起作用

时间:2012-05-08 20:24:45

标签: cakephp model cakephp-2.0 uploader

我正在使用CakePHP 2.1.1和Miles Johnson的Uploader Plugin v 3.5 尽管我认为在尝试卸载FileValidation行为时遇到问题,但它的工作非常好。

我已设置了Uploader.AttachmentUploader.FileValidator行为(请参阅问题的底部)。
afterSave回调中,我现在需要再次保存Post,以便为其他语言环境添加翻译字段。

当我再次保存时,这似乎会导致FileValidation行为出错。我收到错误:
failed to open stream: No such file or directory [APP/Plugin/Uploader/Model/Behavior/FileValidationBehavior.php, line 296]
不知何故,行为再次寻找tmp文件 当我根本没有定义FileValidation行为时,一切顺利。因此,我想在常规save()期间完成工作后禁用该行为,就在我进入第二个save()之前。 因此,afterSave($created)我声明了

$this->Behaviors->unload('FileValidation');
$this->save($data);

错误消失了,但我收到了4个警告:

Warning (512): Could not find validation handler maxWidth for file [CORE/Cake/Model/Model.php, line 3155]  
Warning (512): Could not find validation handler maxHeight for file [CORE/Cake/Model/Model.php, line 3155]
Warning (512): Could not find validation handler filesize for file [CORE/Cake/Model/Model.php, line 3155]
Warning (512): Could not find validation handler required for file [CORE/Cake/Model/Model.php, line 3155]

我也试过$this->Behaviors->disable('FileValidation')但无济于事。 这是行为中的错误(没有正确卸载)或者我没有正确处理卸载?

亲切的问候, 巴特

行为设置:

public $actsAs = array('Uploader.Attachment' => array(
        'file' => array(
            'name'      => 'uniqueFilename',    // Name of the function to use to format filenames
            'baseDir'   => APP,         // See UploaderComponent::$baseDir
            'uploadDir' => 'webroot/img/upload/',           // See UploaderComponent::$uploadDir
            'dbColumn'  => 'uploadPath',    // The database column name to save the path to
            'importFrom'    => '',          // Path or URL to import file
            'defaultPath'   => '',          // Default file path if no upload present
            'maxNameLength' => 30,          // Max file name length
            'overwrite' => false,       // Overwrite file with same name if it exists
            'stopSave'  => true,        // Stop the model save() if upload fails
            'transforms'    => array(),     // What transformations to do on images: scale, resize, etc
            's3'        => array(),     // Array of Amazon S3 settings
            'metaColumns'   => array(       // Mapping of meta data to database fields
                'ext' => 'ext',
                'type' => 'type',
                'size' => 'size',
                'group' => 'group',
                'width' => 'width',
                'height' => 'height',
                'filesize' => 'size',
                'name'=>'name'
            )
        )
    ),
    'Uploader.FileValidation' => array(
        'file' => array(
            'maxWidth' => array(
                'value' => 1000,
                'error' => 'Image too wide. Max 1000px'
            ),
            'maxHeight' => array(
                'value' => 1000,
                'error' => 'Image too high. Max 1000px'
            ),
            'extension' => array(
                'value' => array('gif', 'jpg', 'png', 'jpeg'),
                'error' => 'Mimetype incorrect',
            ),
            'filesize' => array(
                'value' => 1048576,
                'error' => 'Filesize too high. Max 1 MB'
            )
        )
    )
);

2 个答案:

答案 0 :(得分:0)

没有直接相关,但你是否试试另一个文件上传插件?这个可以解决这个问题:http://bakery.cakephp.org/articles/srs2012/2012/03/12/ajaxmultiupload_plugin_for_cake_2_0_x_and_2_1

答案 1 :(得分:0)

不确定这是否会解决您的问题,但我发现(由于某种原因我不知道为什么)如果您在Config / core.php中没有将调试设置为0,则会抛出此错误