我正在使用 CakePHP 2.1.1 和 Miles Johnson 的Uploader Plugin v 3.5。
虽然我认为我在尝试卸载 FileValidation 行为时遇到了问题,但它工作得非常好。
我已经设置了行为Uploader.Attachment
和Uploader.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'
)
)
)
);