0

我正在使用 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'
            )
        )
    )
);
4

2 回答 2

0

没有直接关系,但你想尝试另一个文件上传插件吗?这个可能会成功:http: //bakery.cakephp.org/articles/srs2012/2012/03/12/ajaxmultiupload_plugin_for_cake_2_0_x_and_2_1

于 2012-05-09T22:18:55.057 回答
0

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

于 2013-02-19T21:48:41.197 回答