2
我一直在適應這個例子我自己的形式:http://framework.zend.com/manual/2.1/en/modules/zend.form.file-upload.html爲什麼ZF2 PRG插件返回[fileUploadFileErrorFileNotFound] =>文件未找到?
當我加入我的形式使用Choose File
按鈕我的文件,然後提交表單,我得到這個:
Array
(
[fileUploadFileErrorFileNotFound] => File was not found
)
和變量其內容打印在上面是這個(表格提交後):
$fileErrors = $form->get('character-ref')->getMessages();
可能是什麼問題?我有點不知道這一點。我看着RenameUpload
過濾器和一些網站,但在這一點上缺乏線索。
我的代碼,其中有關:
class CommissionInputFilter implements InputFilterAwareInterface
{
function getInputFilter()
{
$inputFilter = new InputFilter();
//this is the filter that is supposed to make
//PRG Plugin file upload possible
$renameFilter = new RenameUpload(array(
'target' => "./data/uploads/",
'randomize' => true
));
// File Input - I am not sure if this is the way to do it
//some examples do not use FileInput
$fileInput = new FileInput('character-ref');
$fileInput->setRequired(false);
$fileInput->getFilterChain()->attach($renameFilter);
$inputFilter->add($fileInput);
return $inputFilter;
}
}
//code inside controller
public function addAction()
{
$form = new CommissionForm();
$tempFile = null;
$prg = $this->fileprg($form);
if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
return $prg;
} elseif (is_array($prg)) {
//**************************************************
//this line below is where I set my input filter for the form
//the filter that contains PRG Rename pluging supposedly
//One interesting note is if I *Remove* the line below
//then the PRG Plugin keeps the file name as it is supposed to
//**************************************************
$form->setInputFilter((new CommissionInputFilter())->getInputFilter());
if ($form->isValid()) {
$output = new CommissionOutput();
$commission = $output->getCommission($form->getData());
$id = $this->repository->saveCommission($commission);
$view = new ViewModel();
$view->setTemplate('commission/commission/thank_you');
$view->setVariables($prg);
return $view;
} else {
//********************************************************
//My Properly-filled out form ends up here with file errors
//********************************************************
$fileErrors = $form->get('character-ref')->getMessages();
if (empty($fileErrors)) {
$tempFile = $form->get('character-ref')->getValue();
}
}
}
return array(
'form' => $form,
'characterRefFile' => $tempFile
);
}