Issues

ZF-6937: Filters for multiple files

Description

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:


$upload = new Zend_File_Transfer_Adapter_Http();
$upload
    ->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:


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:


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?

Comments

Duplicates ZF-5126

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

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.

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...

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

The ZF documentation linked below shows this should be possible:

http://framework.zend.com/manual/en/…

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.