我正在使用CakePHP 2.1.1和Miles Johnson的Uploader Plugin v 3.5。
雖然我覺得在嘗試卸載FileValidation行爲時遇到問題,但它的工作非常好。unload()CakePHP Uploader插件似乎不起作用
我已經設置了行爲Uploader.Attachment
和Uploader.FileValidator
(請參閱問題的底部)。
在afterSave
回調中,我現在需要再次保存Post
以爲其他語言環境添加翻譯字段。
當我再次保存時,這似乎會在FileValidation
行爲中導致en錯誤。我得到的錯誤:
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'
)
)
)
);
謝謝,我會盡快查看我的平臺的Fileupload部分。 –