ZF-4774: Form's Files doesn't work at all

Issue Type: Patch Created: 2008-11-02T05:53:28.000+0000 Last Updated: 2008-11-13T14:10:20.000+0000 Status: Resolved Fix version(s): - 1.7.0 (17/Nov/08)

Reporter: Adam Kusmierz (raistlin) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

  • Zend_Form

Related issues: Attachments: - File.diff


I've form like this:

<pre class="highlight">
$subForm = new Zend_Form;
        $subForm->createElement('file', 'mp3')
            ->setLabel('Plik mp3')
            ->addFilter('Rename', $options['tmp'] . '/' . md5(microtime(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')
            ->addFilter('Rename', $options['tmp'] . '/' . md5(microtime(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.


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 (…)

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


You have:

<pre class="highlight">
wich receive all table, with all sent files. And you got first element from it. If I uploaded many files, it broke "getValue" (and upload too).

A suggested:

Now you get table with one element, contains only uploaded file which actualy you want. But! It's still table! So next line:

<pre class="highlight">
is always false!
Now, you must get first (and single) element from table:

And, it's as I provided in fix:

<pre class="highlight">
-         $content = current($this->getTransferAdapter()->getFileInfo());
+        $content = $this->getTransferAdapter()->getFileInfo($this->getName());
+        $content = reset($content);

... Now you understand?

Posted by Thomas Weidner (thomas) on 2008-11-02T13:37:56.000+0000

No you're completly wrong.

The code reads:

<pre class="highlight">
        $content = current($this->getTransferAdapter()->getFileInfo($this->getName()));

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.