ZF-4774: Form's Files doesn't work at all
Description
I've form like this:
$subForm = new Zend_Form;
$subForm
->addElements(array(
$subForm->createElement('file', 'mp3')
->setLabel('Plik mp3')
->setDestination($options['tmp'])
->addFilter('Rename', $options['tmp'] . '/' . md5(microtime(true)))
->setRequired(true)
->addValidator('Count', false, 1) // ensure only 1 file
->setMaxFileSize(10 * 1024 * 1024), // limit to 10M
//->addValidator('FilesSize', true, '10MB')
//->addValidator('Extension', true, 'mp3') // only JPEG, PNG, and GIFs
$subForm->createElement('file', 'kar')
->setLabel('Plik kar')
->setDestination($options['tmp'])
->addFilter('Rename', $options['tmp'] . '/' . md5(microtime(true)))
->setRequired(true)
->addValidator('Count', false, 1) // ensure only 1 file
//->addValidator('Extension', true, 'kar,mid,midi')
));
(additionaly: commented validators doesn't work!)
When I send files, I've got ONE, first file and null for second (and it hasn't uploaded). setMutiFile() doesn't work to. To get work above code, should apply my patch. It's get proparly value of "content" in getValue() method from Zend_Form_Element_File class, and save value after receive(). Next time, it uses saved value from protected var.
Comments
Posted by Adam Kusmierz (raistlin) on 2008-11-02T05:54:07.000+0000
Patch to repair Zend_Form_Element_File.
Posted by Matthew Weier O'Phinney (matthew) on 2008-11-02T06:07:02.000+0000
Please test against current trunk. Thomas has been making huge strides in fixing bugs and adding feature to the file upload element since the 1.7.0 PR release, and you may find that the issues have already been corrected.
Posted by Matthew Weier O'Phinney (matthew) on 2008-11-02T06:07:18.000+0000
Assigning to Thomas.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T06:11:22.000+0000
I've always use trunk (http://framework.zend.com/svn/framework/…)
Posted by Adam Kusmierz (raistlin) on 2008-11-02T07:13:50.000+0000
Some improvements.
Posted by Thomas Weidner (thomas) on 2008-11-02T09:13:47.000+0000
Do the proposed code change the behaviour of the validators ? This would wonder me, because the file validators do not use the elements value.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T11:31:04.000+0000
I don't know. Validators doesn't work without my changes neither (as I wrote in description) - my form always fail if I use validators commented in code above.
Posted by Thomas Weidner (thomas) on 2008-11-02T11:49:00.000+0000
So when your code does not change the behaviour, and it works wether with old nor with changed classes, what is the reason of the proposed change ?
Posted by Thomas Weidner (thomas) on 2008-11-02T11:55:03.000+0000
Please try r12266 which is the latest release. Some things have been changed. The latest release should also work with your code.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T11:58:35.000+0000
It not repair validators, if validators doesn't use getValue - I think. But example code above doesn't work with version #12265 from trunk. It returns filename and move to selected directory, only first file. In second (and probably next), I haven't any value (null) nor file moved. My proposed change fix this.
Posted by Thomas Weidner (thomas) on 2008-11-02T12:15:10.000+0000
As I wrote:
Please try r12266 which is the latest release. Your change does not work with latest release, but this release should fix your problem. ;-)
Posted by Adam Kusmierz (raistlin) on 2008-11-02T12:22:58.000+0000
Now I have two nulls in $form->getValues() (mp3 & kar) and none uploaded files.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T12:33:14.000+0000
In Zend/Form/Element/File.php, after line 588# $content = $this->getTransferAdapter()->getFileInfo($this->getName()); add: 589# $content = reset($content); It should fix.
Posted by Thomas Weidner (thomas) on 2008-11-02T13:05:12.000+0000
Sorry, but we are no try-n-error community. ;-)
First you propose to delete the array handling, now you propose to readd it. Do you really know what you want ?
I will readd the old behaviour which, related to your patch, did not work, but must be implemented reading your last comment.
Posted by Thomas Weidner (thomas) on 2008-11-02T13:14:52.000+0000
Ok, please use r12267. I readded multifile handling for getValue().
Posted by Adam Kusmierz (raistlin) on 2008-11-02T13:17:17.000+0000
Uh, sorry. I thought my fix worked ok... And I think it now too :P Maybe it's because my english is poor... Anyway
Look
You have:
Now you get table with one element, contains only uploaded file which actualy you want. But! It's still table! So next line:
And, it's as I provided in fix:
... Now you understand?
Posted by Thomas Weidner (thomas) on 2008-11-02T13:37:56.000+0000
No you're completly wrong.
The code reads:
And this does the same as your 2 last lines... it returns all elements with the actual element's name (can be multiple when using multifile.
And then uses the current one. As we only test if there is any content it does not matter if we have the first or the second one. This does only test if the $_FILES array has been properly initialised or not.
As I said:
PLEASE TRY OUT r12267. The code you gave is from r12265.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T13:45:01.000+0000
Now, after you add "$this->getName()" in param of getFileInfo it works. Thank you.
PS I know, that was r12265, I tried to explain you, where I see error. Nevermind. EOT. You could close it, I think. Thank you.
Posted by Thomas Weidner (thomas) on 2008-11-02T13:54:08.000+0000
Fixed with r12267
Posted by Wil Sinclair (wil) on 2008-11-13T14:10:20.000+0000
Changing issues in preparation for the 1.7.0 release.