0

我有一个 fieldset 实现InputFilterProviderInterface,所以它有这个功能getInputFilterSpecification。该__construct()函数正在添加一个文件元素('logo'),如下所示:

    $this->add(array(
        'name' => 'logo',
        'type' => 'file',
        'attributes' => array(
            'required' => false,
            'class' => 'form-control',
            'id' => 'logo',
        ),
        'options' => array(
            'label' => 'Company Logo: ',
        ),
    ));

在我的getInputFilterSpecification函数中,如何添加 RenameUpload 输入过滤器?

我尝试了以下几种变体,但均未成功:

public function getInputFilterSpecification()
{
    return array(
        
        array(
            'name' => 'logo',
            'filterchain' => array(
                'name' => 'filerenameupload',
                'options' => array(
                    'target' => '/public/images/' . time(),
                ),
            ),
            'required' => false,
        ),
        //... other filters
    }
}

如何添加 FileRenameUpload 过滤器 ( Zend\Filter\File\RenameUpload)?

[编辑]

我已将数组更改为:

        array(
            'name' => 'logo',
            'filters' => array(
                array(
                    'name' => 'filerenameupload',
                    'options' => array(
                        'target' => '/public/images/' . time(),
                    ),
                ),
            ),
            'required' => false,
        ),

哪个“似乎”正在工作,但是我现在收到此消息-

文件 'C:\xampp\tmp\phpDA68.tmp' 无法重命名。处理文件时出错。

可能发生了哪些错误?我如何解决它?

4

2 回答 2

0

此问题是由指定无效的target. 前缀它getcwd()使路径相对于应用程序根目录。

array(
    'name' => 'logo',
    'filters' => array(
        array(
            'name' => 'filerenameupload',
            'options' => array(
                'target' => getcwd() . '/public/images/' . time(),
            ),
        ),
    ),
    'required' => false,
),
于 2016-08-08T10:55:13.433 回答
0

您必须在使用 renameFile 之前创建 dir。

示例: mkdir( $rootPath . '/public/images/' . time() );

于 2019-04-18T16:26:19.240 回答