[英]ZF2.4 File input RenameUpload
我有一個實現InputFilterProviderInterface
,所以它具有功能getInputFilterSpecification
。 __construct()
函數正在添加一個文件元素(“徽標”),如下所示:
$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'無法重命名。 處理文件時發生錯誤。
可能發生什么錯誤? 我如何解決它?
指定無效的target
引起此問題。 使用getcwd()
進行前綴會使路徑相對於應用程序根目錄。
array(
'name' => 'logo',
'filters' => array(
array(
'name' => 'filerenameupload',
'options' => array(
'target' => getcwd() . '/public/images/' . time(),
),
),
),
'required' => false,
),
在使用renameFile之前,您必須已創建目錄。
示例:mkdir($ rootPath。'/ public / images /'。time());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.