> (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)
So your customer sends one file within a form "file.dat" and then you must
receive it multiple times ?
$form->file->receive();
$form->file->receive();
$form->file->receive();
Sorry, but after the first receive there is no file within the temporary
directory of PHP because it's already received.
PHP itself does not allow to receive a file multiple times.
What you are speaking of is to upload a same named file multiple times...
this has nothing to do with receiving the form data multiple times. I still
see no reason why someone should receive a file multiple times.
> * 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()) ?
You have a logical problem:
You want to store the file before you have the database id... how should
that work?
There are only 2 possible ways:
You can eighter get the database id BEFORE you receive/store the file...
between validation and retrievement.
Or you have to rename the file manually AFTER you received it and you have
the database id.
> 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
Bad solution
> 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
Also a bad solution.
> 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
Another bad solution. :-)
> How can I do this without extending and overloading the getValue() method
> of the Zend_Form_Element_File ?
As I said before... between validation and retrievement.
> 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 case that the file is very big, you will have severe performance problems
with this solution.
Think different:
1.) Post
2.) Validation
2.) Create empty database entry and get db-id
3.) Set id on form and filename
4.) getValues()
As I said before...
When you want to name the filename after the database id you have only 2
ways:
Eighter get the id BEFORE retrievement, as shown above.
Or rename the file AFTER you inserted into your database (possible
performance problems).
> 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
Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
没有评论:
发表评论