ZF-10046: Rename Filter not working correctly if abbreviated form used

Issue Type: Bug Created: 2010-06-24T01:31:06.000+0000 Last Updated: 2012-01-12T09:25:44.000+0000 Status: Reopened Fix version(s): - 1.10.7 (28/Jul/10)

Reporter: Julian Pustkuchen (anybody) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

Related issues: Attachments:


Please notice that there seems to be a heavy bug if you try to use the "rename" filter on each file before "receive" (to prevent problems with files being uploaded that have identical the same name (but don't have to be the same file)):

Register a filter object instead of the 3-parameter-style to make it work, as following:

<pre class="highlight">

//Dateien individuell umbenennen, sonst gibt es Probleme mit gleichnamigen Dateien.
        $files = $parFileTransfer->getFileInfo();
        //Achtung, Dateien sind an dieser Stelle noch temporär!
        $i = 0;
        foreach($files as $key => $fileInfo){   
                //Jede Datei in ein eigenes, zufälliges Verzeichnis verschieben um Namenskonflikte zu verhindern.
                    new Zend_Filter_File_Rename(
                        array(  'source'    =>  $fileInfo['tmp_name'],
                                'target'    =>  $i.$key)


<-- Result absolutely OK!

The following did not identify the files correctly, even if it should! Result was, that all files were named the same (identity seems to be set wrong in rename). The rename filters were wrongly applied on all files though.

DO NOT USE (this part):

<pre class="highlight">
$parFileTransfer->addFilter('Rename', $i.$key, $fileInfo['tmp_name']);


Posted by Julian Pustkuchen (anybody) on 2010-06-24T01:32:29.000+0000

Changed code stlyle

Posted by Julian Pustkuchen (anybody) on 2010-06-24T02:27:09.000+0000

Well, as I found out, there is another problem:

Zend_File_Transfer_Adapter_Abstract can only handle one filter of each type, which is a problem if you have to act on file basis, not on general upload basis:

In "addFilter" this is being done by: "$this->_filters[$class] = $filter;"

But it should be a construction like: "$this->_filters[$class][] = $filter;" to act on file basis.

The current implementation only uses the last added filter, which is not the true meaning of "addFilter", but of "setFilter" or something like this.

As described above you have to fix this with no doubt, because else you are never able to upload files named same!!! (not even using this workaround!!) So I expect this as HIGHLY CRITICAL!

Posted by Julian Pustkuchen (anybody) on 2010-06-24T02:30:30.000+0000

Changed priority because this bug affects general functionality of uploading same named files and the code doesn't work as expected/documented!

Posted by Thomas Weidner (thomas) on 2010-06-27T07:39:15.000+0000

Degrading priority.

The given example implies that the used code is wrong.

Posted by Thomas Weidner (thomas) on 2010-06-27T07:46:35.000+0000

Using the temporary name instead of the file element does not work when you use the code given within the manual. This works only when you have another workflow which is not officially documented.

You did not point out when $parFileTransfer should be. You did not point out how you create the form. You did not point out how you receive the files.

The actual example can not be verified. Please add some code which can be reproduced to see where you have problems.

Posted by Julian Pustkuchen (anybody) on 2010-06-27T13:09:44.000+0000

Firstofall, thank you for your quick reply.

Please give me a working example, how to handle a file upload with files having the same name. In my oppinion it is just not possible using Zend_File_Transfer and that's really bad, isn't it?

If you were able to add several rename filters on file basis, not just one on upload basis, you could use my workaround, but because only the last rename filter can be used (override in ZF as described above) this doesn't work.

I think it is easier if you try to find a solution for the "same file name"-problem yourself, perhaps you will have the same problems. If not, it would be nice if you could add your solution to the documentation and post ist here, because this is a major problem in my eyes.

Posted by Thomas Weidner (thomas) on 2010-07-12T12:05:49.000+0000

I think you are misunderstanding what issues are.

Creating an issue does not mean that you get your code fixed and developed an solution because you don't know how it works.

It is not my work to show you how you can reproduce your problem.

Posted by Thomas Weidner (thomas) on 2010-07-12T12:06:55.000+0000

Closing as not reproduceable with the given example

Posted by Julian Pustkuchen (anybody) on 2010-07-12T12:23:59.000+0000

So just two last questions, which I hope you will answer: Don't you think that it is bad, that with this Component you are not able to upload two files with the same name at once?

Don't you think that it is bad, that there can only be one filter for each type even if the function is called addFilter (which is misleading)?

And please don't say I don't know how it works, thats not true. If you had a look yourself, you would know.

Posted by netroby (netroby) on 2012-01-12T09:21:42.000+0000

following code should work for multiple files upload.

<pre class="highlight">
 $target_path =  '/var/www/uploads/';
            $adapter = new Zend_File_Transfer_Adapter_Http();
            $adapter->addValidator('Size', false, 102400);
            $adapter->addValidator('IsImage', false, array(

            $files = $adapter->getFileInfo();
            foreach ($files as $file => $info) {
                if ($info['name'] != '') {
                    if ($adapter->isValid($file)) {
                        //generate new filename , you can using random hash filename, output 32acb74d.jpg
                        $newFileName = $this->_getNewFileName($info);
                        $adapter->clearFilters()->addFilter(new Zend_Filter_File_Rename( array(
                                'source' => $info['tmp_name'],
                                'target' => $target_path . $newFileName,
                                'overwrite' => TRUE
                        if (!$adapter->receive($file)) {
                        $this->_addEnvPhoto($this->_getDisplayUrl() . '/' . $newFileName, $info);

Posted by netroby (netroby) on 2012-01-12T09:25:44.000+0000

This issue like to say :

when using Zend_File_Transfer handle multiple files uploads, we do not know how to move uploads files to right directory.

by document, seems we could using Zend_Filter_File_Rename , but it seems not working correctly.

would you please show me a short code snippet , handle multiple files upload, move upload files to right target directory? (using ZendFramwork, Zend_File, Zend_Filter and etc)

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.