I am attempting to upload a file using Zend Framework 1.8 and I get some errors. Here is the code snippet:
The form element:
$element = new Zend_Form_Element_File('doc');
$element->setLabel('Upload an image:')
->setDestination('/path/to/my/upload/folder');
$element->addValidator('Count', false, 1);
$element->addValidator('Size', false, 102400);
$element->addValidator('Extension', false, 'jpg,png,gif,doc,docx,xls,xlsx,txt');
$this->addElement($element);
The code for handling the upload:
$adapter = new Zend_File_Transfer_Adapter_Http();
if (!$adapter->receive()) {
$messages = $adapter->getMessages();
echo implode("\n", $messages);
}
This works fine and the file is uploaded but I get the error "The file 'doc' was illegal uploaded, possible attack".
I managed to get past this problem by not creating a new Zend_File_Transfer_Adapter_Http() but instead using:
$adapter = $form->doc->getTransferAdapter();
With this modification, the first error disappears but now I have an error saying I have provided 2 files instead of one (probably its reading the temp) and when I adjust the validator to accept two files I then get the arror saying "The file 'doc' was not found" and the upload now fails completely.
Please help