2008年8月25日星期一

Re: [fw-mvc] Zend_Form_Element_File upload issues

-- Adam Jensen <jazzslider@gmail.com> wrote
(on Monday, 25 August 2008, 12:55 PM -0500):
> On Mon, Aug 25, 2008 at 12:31 PM, Thomas Weidner <thomas.weidner@gmx.at> wrote:
> I can not speak for Zend_Form, but the file component itself, which has
> nothing to do with Zend_Form, moves a file if all validators attached to
> this file are ok. Zend_File_Transfer can not know about other validators
> from other components.
>
>
> Fair enough. But might it be possible to add, say, some sort of validation
> callback to the file transfer adapter so that it could be made aware (at
> runtime) of any larger processes it might be a part of? For instance, a file
> validator that takes a Zend_Form object in its constructor and whose isValid()
> method simply checks if the rest of the form is valid (accounting, of course,
> for recursion problems)?

This is a very, very difficult concurrency nut to crack, and there are
better ways to do this. Probably the best idea is to check after form
validation -- if the form did not pass validation, and the element has
no validation errors, then you should manually delete the newly uploaded
file.

> Also, when a user submits a form also attached files are uploaded. This is
> due to the HTTP protocol, where files are included in the form itself.
> There is no way of seperating them without seperating the data form and the
> upload form.
>
>
> True, but the initial upload is temporary. If you don't move the file to a
> permanent location (with, e.g., move_uploaded_file() or copy()), it's deleted
> after the script is processed. My concern is that that temporary file is
> automatically moved to its final destination (assuming it passes validation),
> potentially causing data integrity issues if the upload is part of a larger
> process.

Note my above algorithm.

> Normally I would propose to do all validations before and at last the file
> validations. Maybe you can arrange your validations.
>
>
> Is it possible within Zend_Form to halt the entire form's validation process
> when one validator fails? I.e., if the file element is at the end of the form
> and an earlier element isn't valid, don't fire the file element validators?

No, we don't have this functionality, but we _may_ be able to implement
it. Please file a feature request on the tracker for this.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: