2009年3月30日星期一

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

Sorry
(I know you're starting to hate me but I have to understand),
my last question about the file upload:

Some hints:
* File elements don't have a value
OK

* Receive a file multiple time does not make sense
FALSE
I have customers that send to my application files called: update.dat
constantly (ever the same name and sometime simultaneously)

* Use filters to change file content or file data while receiving
(including file name for example)
how can filter by Rename if I will know the name only AFTER the "insert
into" Db operation ... (I mean the lastInsertId()) ?

if I do
$id = $model->insert($form->getValues())
the fields are filtered but the file is just uploaded (moved) and can't
be renamed as I want because I will know the ID only when the insert()
function returns

if I do
$id = $model->insert($request->getPost())
The fields and the file are not filtered

In my case the flow is:
1) Post the form
2) Filter the fields (including the files uploaded)
3) Insert into Db
4) Get the Last Insert Id
5) handle (move/rename as {$id}.jpg) the file uploaded

and NOT
1) Post the form
2) Filter the fields (including the files uploaded)
3) handle (move/rename as {$id}.jpg) the file uploaded
4) Insert into Db
5) Get the Last Insert Id

How can I do this without extending and overloading the getValue()
method of the Zend_Form_Element_File ?

The only way I've found is:
1) rename first the file as the session_id() adding a filter Rename =>
APPLICATION_PATH . '/tmp/' . session_id();
2) make the $id = $model->update($form->getValues()) ; // here rename
the file and filter the fields
3) rename(APPLICATION_PATH . '/tmp/' . session_id(), $id.'jpg'); //
re-rename as I wish

In this case I have to manage 2 tmp file ...
1 made by php file upload called /tmp/php123.tmp ...
then renamed to tmp/SESSIONID by the filter ...
and then manualy renamed to ID.jpg

... and hope that no1 else have the same session_id()

:\ sad solution

Thomas, congratulations for your job in Zend Framework ...
I've read all your Blacksheeps paradise
http://www.thomasweidner.com/flatpress/category/file-transfer/
but I didn't find the 3-6 lines of code that resolv this problem

bye

Simone

没有评论: