Zend file upload error

Posted by jgnasser on Stack Overflow See other posts from Stack Overflow or by jgnasser
Published on 2010-05-23T03:22:51Z Indexed on 2010/05/23 3:30 UTC
Read the original article Hit count: 419

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about fileupload

Related posts about zend-form