通过Miles Johnson Uploader上传时无法重命名文件

时间:2011-07-28 20:06:46

标签: cakephp

在我的文件模型上:

var $actsAs = array(
    'Uploader.FileValidation' => array(
        'file' => array(
            'extension'     => array('gif', 'jpg', 'png', 'jpeg'),
            'filesize'      => 5242880,
            'required'      => true
        )
    ),
    'Uploader.Attachment' => array(
        'file' => array(
            'uploadDir'     => 'upload/',   // Where to upload to, relative to app webroot
            'dbColumn'      => 'path',  // The database column name to save the path to
            'maxNameLength' => 30,      // Max file name length
            'overwrite'     => true,    // Overwrite file with same name if it exists
            'name'          => '',  // The name to give the file (should be done right before a save)
            'transforms'    => array()  // What transformations to do on images: scale, resize, etc
        )
    )
);

在控制器上:

$this->File->Behaviors->Attachment->update('File', 'file', array('name' => 'testing')));
            if ($this->File->save($this->data)) {

文件上传正常,记录保存在数据库中。但是我想重命名该文件以避免人们错误地找到档案。

谢谢!

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。您可以在保存之前执行相同的任务。

$this->data['File']['file']['name'] = 'myNewName';