2
votes

Can someone please kindly explain to me what really happen when you call the function setDestination()? According to the Zend "documentation" both of these should work, however only the first case puts the file where I wanted. The second just ditch it in /tmp

Case 1:

$file = new Zend_Form_Element_File('fileupload');
$file->setDestination('/some/pathsomewhere/');

This works fine, the file will get uploaded to /some/pathsomewhere

Case 2: (after checking isValid($_POST))

$upload = new Zend_File_Transfer_Adapter_Http();
$upload->setDestination('/some/pathsomewhere/');
try {
    $upload->receive();
}

no exception. File is ditched in /tmp

I don't understand why the file ends up in /tmp in Case 2 :(

2

2 Answers

6
votes

Hopefully this will help someone.

If you use Zend_Form_Element_File to construct your HTML. You need to specify:

$element->setValueDisabled(true);

If you do not call setValueDisabled, it will upload the file automatically on submit. So if you want to be able to control where to place the file on the server set this value to true and manually call ->receive(). I wish the documentation would tell you this. I love Zend but starting to hate the "you should know" altitude of the documentation.

1
votes

Just tested it with Zf 1.10 and it works fine:

    public function upAction()
    {
        if ($this->getRequest()->isPost()) {

            $upload = new Zend_File_Transfer_Adapter_Http();
            $upload->setDestination('c:/temp/');

            if ($upload->receive()) {
                echo "Success";
            }
        }
    }

File is now in C:/temp/ without any problems. Possible an bug in an older ZF version? I think there were one till 1.9.x