2009年3月28日星期六

Re: [fw-mvc] form->getValues and file upload

For me it's not helpfull. Your code does not work because you use false
assumptions.

You should look into the manual (Zend_Form_Element_File and
Zend_File_Transfer)
and take a look into this blog: http://www.thomasweidner.com into the file
transfer section.

Some hints:
* File elements don't have a value
* Receive a file multiple time does not make sense
* Use filters to change file content or file data while receiving (including
file name for example)

A solution for this task was asked and sent several times in past and it did
not include the extension of 2 core components but only 3-6 lines of code.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "Ed Lazor" <edlazor@internetarchitects.biz>
To: "Thomas Weidner" <thomas.weidner@gmx.at>
Cc: <fw-mvc@lists.zend.com>
Sent: Saturday, March 28, 2009 9:43 PM
Subject: Re: [fw-mvc] form->getValues and file upload


> On Sat, Mar 28, 2009 at 1:40 PM, Thomas Weidner <thomas.weidner@gmx.at>
> wrote:
>> Ed,
>>
>> I don't quite understand what you mean because I replied to Simone.
>> You never sent a line of code and I was just replying to the extension of
>> 2
>> base classes from Simone which is not necessary.
>
> Sorry, I see now that it went just to Simone, but here it is now.
>
> -Ed
>
>
>
> If it helps, here's more details on what originally brought this up.
>
> I was processing a form that included a file upload. Most of the data
> from the form was going to be used in creating a new database record.
> The final name of the uploaded file was going to include the ID of the
> new database record. Something like this:
>
> if ($form->isValid($request->getPost()) {
> $application = new Application();
> // save new record
> $id = $application->saveEntry($form->getValues());
>
> // use new id to process and save attached file...
> $upload = new Zend_File_Transfer();
> $upload->receive();
> // more processing, etc...
> }
>
>
> Receiving the uploaded files would fail, because $form->getValues()
> had already been called and the files were no longer in the tmp
> directory (which is odd, IMHO).
>
> My solution was something like this:
>
> if ($form->isValid($request->getPost()) {
> $application = new Application();
> // save new record
> $data = array();
> $data['field1'] = $form->getValue('field1');
> ... extra lines for building the data array
> $id = $application->saveEntry($data);
>
> // use new id to process and save attached file...
> $upload = new Zend_File_Transfer();
> $upload->receive();
> // more processing, etc...
> }
>
>
> IMHO, I consider that a work around solution, because I should be able
> to just call $form->getValues(). Another option would be to receive
> the files before saving the entry. I honestly didn't try that
> approach though. I just put the work around in place until I could
> figure out what was going on with the getValues method, because I
> first thought I was doing something wrong or perhaps there was a bug
> in getValues.
>
> What do you think?
>
> Thomas, is this helpful at all?
>
> -Ed

没有评论: