ZF-5990: getFileName returns wrong file name (for form with 2 elements: file and file_two)


I added two times a Zend_Form_Element_File, one with the name 'file', the other with the name 'file_two'. When asking the Zend_Transfer_Adapter for getFileName('file'), I get an array with both elements (fair enough; though I still find this weird). However, when asking for getFileName(), it returns the following:

array (
  'file_two' => 'D:\\tmp\\php\\uploads\\size-256.txt',
  'file' => 'Array\\size-1024.txt',

("D:\tmp\php\uploads\" being my upload_tmp_dir).

Problem is, of course, the second element, which has 'Array' instead of the directory. This is because when asking for getDestination($file) (which getFileName does), it returns an array with both elements:

array (
  'file_two' => 'D:\\tmp\\php\\uploads',
  'file' => 'D:\\tmp\\php\\uploads',

I've tested with 1.7.6 as well as the SVN version from… (revision 142740).

You can, of course, make the name yourself with getFileInfo(), concatenating the destination, a DIRECTORY_SEPARATOR and the name. However, from what I see, that file doesn't exist either.


The reason is that "_" is used as seperator for SubForms... Therefor it looks internally which other file elements are also within the "file" SubForm "file_1", "file_2" and so on... and returns them all.

Simply use another seperator because "_" is also used overall the complete framework as directory seperator, and within several other places.

Isn't the underscore like the most used separator for form element names? Mostly because those names match columns in a database somewhere? Maybe it's an option to make the separator configurable?

And regardless of what's behind it, shouldn't getFileName() return proper results, even if it means returning files from subforms? From what I gather, the Zend_File_Transfer_Adapter_Abstract deals with all uploaded files anyhow.

I agree with Johan, this should be resolved, one way or another.

Please dont discuss here useless things. :-) If I would not have seen this as issue I would already have closed it. I just wanted to give a quick solution as we can only fix this for the next release which is earliest in 6 weeks.

<?php echo $form->render(new Zend_View());?>

I've tinkered around with your example, couldn't (at first) find the problem. However; if you change the order of the elements:





The bug surfaces, using either Zend 1.7.6 or revision 14274.

Purely cosmetics; used the ``` tag to display the results better.

"Purely cosmetics;" -> I meant I update the issue summary, it looked weird without the code tags.

Fixed with r14287.