Download file using zend framework 1.7.4

I am trying to upload a file using Zend Framework 1.7.4, but was not successful. I read the Akrabat tutorial , which was useful, but when I used these methods in my project, I could not get it to work.

+5
source share
3 answers

The link you posted is just a Zend Framework tutorial and does not update after ZF 1.5.

In any case, once you get started with Zend, this is a sample code that you will use to get the download. The posting form must contain the correct components for uploading files.

//validate file
//for example, this checks there is exactly 1 file, it is a jpeg and is less than 512KB
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Count', false, array('min' =>1, 'max' => 1))
       ->addValidator('IsImage', false, 'jpeg')
       ->addValidator('Size', false, array('max' => '512kB'))
       ->setDestination('/tmp');

if (!$upload->isValid()) 
{
    throw new Exception('Bad image data: '.implode(',', $upload->getMessages()));
}

try {
        $upload->receive();
} 
catch (Zend_File_Transfer_Exception $e) 
{
        throw new Exception('Bad image data: '.$e->getMessage());
}

//then process your file, it path is found by calling $upload->getFilename()
+24

enctype "multipart/form-data". Zend_Form,

$form->setAttrib('enctype', 'multipart/form-data');

, Zend_Form::setDestination , :

// Deprecated:
// $upload->setDestination('/tmp');
// New method:
$upload->addFilter('Rename', '/tmp');
+8
    $this->setAction('/sandbox/example/form')->setEnctype('multipart/form-data')->setMethod('post');

    $photo = new Zend_Form_Element_File('photo');
    $photo->setLabel('Photo:')->setDestination(APPLICATION_PATH ."/../public/tmp/upload");

    $this->addElement($photo);

You can set any destination example $ photo-> setLabel ('Photo:') → setDestination (APPLICATION_PATH. "/../Data");

0
source

All Articles