ZF-6937: Filters for multiple files

Issue Type: Improvement Created: 2009-06-05T16:03:08.000+0000 Last Updated: 2012-02-22T13:12:31.000+0000 Status: Open Fix version(s): Reporter: Adam Kusmierz (raistlin) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

Related issues: - ZF-5126



I want to upload multiple files (for example 2 fields, named formFile1 and formFile2 and sent by HTML Form's Input). Every file should have different name, for example targetFileName1.ext (for formFile1) and targetFileName2.ext (for formFile2). So I wrote in controller:

<pre class="highlight">
$upload = new Zend_File_Transfer_Adapter_Http();
    ->addFilter('Rename', array(
        'target' => $path . 'targetFileName1.ext'
        ), 'formFile1')
    ->addFilter('Rename', array(
        target' => $path . 'targetFileName2.ext'
        ), 'formFile2')

if (!$upload->receive())  {
    $messages = $upload->getMessages();
    echo $messages;

and html:

<pre class="highlight">

But after submit this I've got php error: "Zend_Filter_Exception: File '\tmp\php9914.tmp' could not be renamed. It already exists. in \var\www\test\library\Zend\Filter\File\Rename.php on line 160". Why? Because of it:

<pre class="highlight">
725:        $this->_filters[$class] = $filter;
726:        $files                  = $this->_getFiles($files, true, true);
727:        foreach ($files as $file) {
728:            $this->_files[$file]['filters'][] = $class;
729:        }

It "caches" in some way used filters, so I can't use different filter (precisely same filter with different options) for different files. Why?


Posted by Thomas Weidner (thomas) on 2009-06-05T16:41:32.000+0000

Duplicates ZF-5126

Posted by Thomas Weidner (thomas) on 2009-06-06T01:10:21.000+0000

Changed from Bug to Improvement. Manual clearly states that this is not possible.

Posted by Stijn Huyberechts (huyby) on 2009-08-13T02:01:13.000+0000

I'm experiencing the same problem. Trying to rename multiple files using the Rename filter. But as described by Adam, it's not possible to actually add a new filter of the same type more than once. Filters of the same type keep overwriting each other.

I do see the use case where the current behaviour of Zend_File_Transfer_Adapter_Abstract::addFilter() is needed. But it should also cover the use case where you want a unique filter, based on the options parameter, for one or more files.

Posted by Tim Ruffles (timruffles) on 2010-02-16T02:58:25.000+0000

Far from "Manual clearly states that this is not possible"...the manual currently uses the expected, behaviour of multiple filters specified by file as an example:

$upload->addFilter('Rename', 'C:\picture\newjpg', 'file1') ->addFilter('Rename', 'C:\picture\newgif', 'file2');

which, of course, doesn't work.

It comes with the note: 'Note: Note that even though setting the same filter multiple times is allowed, doing so can lead to issues when using different options for the same filter'

The manual really should be updated or this should be fixed. Really doesn't make you warm to the framework...

Posted by Ashleigh Vincent (avincent) on 2012-02-22T13:12:31.000+0000

I second that this is a bug, not an improvement.

The ZF documentation linked below shows this should be possible:…

That is exactly what I want to do, but of course this bug means the final parameter is ignored it seems.

Even if this was decided that filters should not be called on two separate files in this manner then why does the addFilter not throw some sort of error? Instead it just applies the last rename filter you set to all files in the current transfer, even though you specified the filter should only apply to a particular file.

Have you found an issue?

See the Overview section for more details.


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

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