views:

133

answers:

2

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 :(

A: 

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

ArneRie
I am also using 1.10 on Linux. Did you try any other path other than c:/temp? Another thing I noticed in the documentation is that they mentioned some gerbish about using Zend_Form and Zend_Transfer together will not work. The Zend_Transfer section is terrible. Example #7 doesn't even work because they set $update to null before accessing it. Did you use $file = new Zend_Form_Element_File('fileupload'); to construct the form element or did you do it using standard HTML? I constructed my form using Zend_Form_Element_File.
Cong
Its an pure html form. Nothing with Zend Form.
ArneRie
A: 

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.

Cong