[英]ZF2.4 File input RenameUpload
I have got a fieldset implementing InputFilterProviderInterface
, so it has the function getInputFilterSpecification
. 我有一个实现
InputFilterProviderInterface
,所以它具有功能getInputFilterSpecification
。 The __construct()
function is adding a file element ('logo') like so: __construct()
函数正在添加一个文件元素(“徽标”),如下所示:
$this->add(array(
'name' => 'logo',
'type' => 'file',
'attributes' => array(
'required' => false,
'class' => 'form-control',
'id' => 'logo',
),
'options' => array(
'label' => 'Company Logo: ',
),
));
In my getInputFilterSpecification
function how do I add the RenameUpload input filter? 在我的
getInputFilterSpecification
函数中,如何添加RenameUpload输入过滤器?
I have tried several variations of the following without success: 我尝试了以下几种变体,但均未成功:
public function getInputFilterSpecification()
{
return array(
array(
'name' => 'logo',
'filterchain' => array(
'name' => 'filerenameupload',
'options' => array(
'target' => '/public/images/' . time(),
),
),
'required' => false,
),
//... other filters
}
}
How do I add the FileRenameUpload filter ( Zend\\Filter\\File\\RenameUpload
)? 如何添加FileRenameUpload过滤器(
Zend\\Filter\\File\\RenameUpload
)?
I have changed the array to: 我将数组更改为:
array(
'name' => 'logo',
'filters' => array(
array(
'name' => 'filerenameupload',
'options' => array(
'target' => '/public/images/' . time(),
),
),
),
'required' => false,
),
Which "appears" to be working, however I am now getting this message - 哪个“似乎”可以正常工作,但是我现在收到此消息-
File 'C:\\xampp\\tmp\\phpDA68.tmp' could not be renamed.
文件'C:\\ xampp \\ tmp \\ phpDA68.tmp'无法重命名。 An error occurred while processing the file.
处理文件时发生错误。
What errors could have occurred? 可能发生什么错误? How do I fix it?
我如何解决它?
This issue is being caused by specifying an invalid target
. 指定无效的
target
引起此问题。 Prefixing it with getcwd()
makes the path relative to the application root. 使用
getcwd()
进行前缀会使路径相对于应用程序根目录。
array(
'name' => 'logo',
'filters' => array(
array(
'name' => 'filerenameupload',
'options' => array(
'target' => getcwd() . '/public/images/' . time(),
),
),
),
'required' => false,
),
You must have created dir before use renameFile. 在使用renameFile之前,您必须已创建目录。
Example: mkdir( $rootPath . '/public/images/' . time() ); 示例:mkdir($ rootPath。'/ public / images /'。time());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.