Zend Framework

Zend_Form_Element_File problem on automated receive of multiple files

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: 1.8.0
  • Fix Version/s: 1.8.2
  • Component/s: Zend_Form
  • Labels:
    None

Description

Hi,

If using the automated receive feature as per example we are experiencing one problem if the uploaded files have the same name. The files are overwrited....

elements.media.type = "file"
elements.media.options.label = "Imagini"
elements.media.options.multifile = 5
elements.media.options.destination = PUBLIC_PATH "/media/categories/"

So if i upload into two fields two files having same name then... Voila... only one file would be into destination folder...

Activity

Hide
Matthew Weier O'Phinney added a comment -

Assigning to Thomas

Show
Matthew Weier O'Phinney added a comment - Assigning to Thomas
Hide
Thomas Weidner added a comment -

I've searched the complete manual... the mentioned example with the code you gave does not exist.

So the question is:
When you define 5 files and store them in the same directory how should the file element know what to do without additional rules ?

You could for example define a rewrite filter, react on duplicate files or use different folders.

Also, when you have 2 identical files then your form will return an error... one file is stored, but the other 4 files can not be stored if they already exist. So you will know that there is something wrong, the problem will not be supressed.

Show
Thomas Weidner added a comment - I've searched the complete manual... the mentioned example with the code you gave does not exist. So the question is: When you define 5 files and store them in the same directory how should the file element know what to do without additional rules ? You could for example define a rewrite filter, react on duplicate files or use different folders. Also, when you have 2 identical files then your form will return an error... one file is stored, but the other 4 files can not be stored if they already exist. So you will know that there is something wrong, the problem will not be supressed.
Hide
Cristian Bichis added a comment -

As i posted also in your blog, the problem is the filters are added only if i use receive() manually....

So if i rather use receive automatically the problem would continue to exist no matter what...

I think filters should work also for automated case, not just for manually receiving files...

We are actually "making less" than PHP does. PHP ensures the files are not overwrited... With current approach we are just breaking this...

Show
Cristian Bichis added a comment - As i posted also in your blog, the problem is the filters are added only if i use receive() manually.... So if i rather use receive automatically the problem would continue to exist no matter what... I think filters should work also for automated case, not just for manually receiving files... We are actually "making less" than PHP does. PHP ensures the files are not overwrited... With current approach we are just breaking this...
Hide
Thomas Weidner added a comment -

The question is:
How do you expect that you are getting the values from a form ?
You must call a method to get values and a file element has as value a file.

If you call receive() to get the file, or if you call getValues(), it's the same. How are you getting other values from the form? I expect that you are calling getValues().

And as you are speaking of PHP... with PHP you must call move_uploaded_file to get the file, which is also a method. I can't see a difference in calling one method, regardless of it's name.

Filters are attached on both methods... calling receive() and calling getValues(). There is no difference.
So what do you want to do?
I am missing additional information.

Show
Thomas Weidner added a comment - The question is: How do you expect that you are getting the values from a form ? You must call a method to get values and a file element has as value a file. If you call receive() to get the file, or if you call getValues(), it's the same. How are you getting other values from the form? I expect that you are calling getValues(). And as you are speaking of PHP... with PHP you must call move_uploaded_file to get the file, which is also a method. I can't see a difference in calling one method, regardless of it's name. Filters are attached on both methods... calling receive() and calling getValues(). There is no difference. So what do you want to do? I am missing additional information.
Hide
Thomas Weidner added a comment -

And related to "the file will be overwritten"...

PHP manual for move_uploaded_file states:
"If the destination file already exists, it will be overwritten. "

So this is correct and expected behaviour.
You can prevent this by using the rename filter which can be set to disallow overwriting files.

Show
Thomas Weidner added a comment - And related to "the file will be overwritten"... PHP manual for move_uploaded_file states: "If the destination file already exists, it will be overwritten. " So this is correct and expected behaviour. You can prevent this by using the rename filter which can be set to disallow overwriting files.
Hide
Cristian Bichis added a comment -

"Filters are attached on both methods... calling receive() and calling getValues(). There is no difference."

Your blog post says:

http://www.thomasweidner.com/flatpress/2009/04/17/recieving-files-with-zend_form_element_file/

"Remember, to have this working you need to call setValueDisabled() otherwise the file is transferred when calling getValues(). When you omit the call then your file will be transferred, due to getValues(), but it will not be renamed, because the rename filter was not available at the time, the file has been received."

So according to text rename filters are available only when receive is called manually... Not when doing directly with getValues() and setValueDisabled() not called....

Show
Cristian Bichis added a comment - "Filters are attached on both methods... calling receive() and calling getValues(). There is no difference." Your blog post says: http://www.thomasweidner.com/flatpress/2009/04/17/recieving-files-with-zend_form_element_file/ "Remember, to have this working you need to call setValueDisabled() otherwise the file is transferred when calling getValues(). When you omit the call then your file will be transferred, due to getValues(), but it will not be renamed, because the rename filter was not available at the time, the file has been received." So according to text rename filters are available only when receive is called manually... Not when doing directly with getValues() and setValueDisabled() not called....
Hide
Thomas Weidner added a comment -

You have to read the complete blog and not only one part of it.
The sentences above in my blog describes how you can make getValues() NOT to receive the file, which is default behaviour. And the sentence you are referring to is a comprehensive note of the above description to make getValues() not receive the file.

All depends on which methods and parameters are used.
As you have still not given any additional information than a ini file there is no way to help.

Again:
Rename filters ARE called when calling receive. There is per default no difference if you call it automatically or manually. When you switch off the automatic by using setValueDisabled() then you have decided to do so.

So any changed behaviour according to your call is intentionally and wished by you.

Without additional information I must conclude that you are using default behaviour. Which means that filters are called on both methods.

Show
Thomas Weidner added a comment - You have to read the complete blog and not only one part of it. The sentences above in my blog describes how you can make getValues() NOT to receive the file, which is default behaviour. And the sentence you are referring to is a comprehensive note of the above description to make getValues() not receive the file. All depends on which methods and parameters are used. As you have still not given any additional information than a ini file there is no way to help. Again: Rename filters ARE called when calling receive. There is per default no difference if you call it automatically or manually. When you switch off the automatic by using setValueDisabled() then you have decided to do so. So any changed behaviour according to your call is intentionally and wished by you. Without additional information I must conclude that you are using default behaviour. Which means that filters are called on both methods.
Hide
Thomas Weidner added a comment -

Closing issue due to non-response.

As result of the discussion the following note:

  • The mentioned problem of overwriting existing uploaded files is default behaviour of PHP
  • You can change this behaviour by using the rename filter with the "overwrite" option
  • Automatic rename of duplicated files is part of another issue regarding the rename filter
Show
Thomas Weidner added a comment - Closing issue due to non-response. As result of the discussion the following note:
  • The mentioned problem of overwriting existing uploaded files is default behaviour of PHP
  • You can change this behaviour by using the rename filter with the "overwrite" option
  • Automatic rename of duplicated files is part of another issue regarding the rename filter

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: