ZF-6851: Zend_File_Transfer_Adapter_Http rename filter issues, it clears the path set

Description

When you add a Rename Filter to the Transfer Adapter, it clears the path, the problem is here:


                $filename = $directory . $content['name'];
                $rename   = $this->getFilter('Rename');
                if ($rename !== null) {
                    $filename = $rename->getNewName($content['tmp_name']);
                    $key      = array_search(get_class($rename), $this->_files[$file]['filters']);
                    unset($this->_files[$file]['filters'][$key]);
                }

Afterwards this point, if there is a custom path move_uploaded_file doesn't recognize it, a solution is to add the directory after the rename:


                $filename = $content['name'];
                $rename   = $this->getFilter('Rename');
                if ($rename !== null) {
                    $filename = $rename->getNewName($content['tmp_name']);
                    $key      = array_search(get_class($rename), $this->_files[$file]['filters']);
                    unset($this->_files[$file]['filters'][$key]);
                }
                
                $directory   = '';
                $destination = $this->getDestination($file);
                if ($destination !== null) {
                    $directory = $destination . DIRECTORY_SEPARATOR;
                }
                $filename = $directory . $filename;

Comments

Please provide a example of what you are doing. Just commenting ZF source code does not enable us to reproduce the behaviour.

Ok:


               $image = $this->_form->image;
        $image->setDestination($this->_iconPath)
                  ->addFilter('Rename', 'Icon_'.$pKey);
        if (!$image->receive()) {
            // Ups a error
            $this->_helper->FlashMessenger('error'));
        } else {
            // Update the received row
            $icono = $this->_model->find($pKey)->current();
            $icono->imagen = $image->getFileName(null, false);
            $icono->save();
        }

Upon calling receive I have noticed that $icono->imagen contains ./Icon_1 (if I get it with the path) and I see no file on the upload dir, upon debugging, the error was caused after the rename of the file, after the code entering:


$filename = $directory . $content['name'];
                $rename   = $this->getFilter('Rename');
                if ($rename !== null) {
                    $filename = $rename->getNewName($content['tmp_name']);
                    $key      = array_search(get_class($rename), $this->_files[$file]['filters']);
                    unset($this->_files[$file]['filters'][$key]);
                }

$filename contained only "Icon_1" not "/path/to/uploads/Icon_1" as expected.

You know that the Rename filter has to be used with the complete path ? The examples in the manual and also the blog do not show any other usage nor has this been supported in past. By omitting the path at the rename filter you said to use the actual path which is the temporary upload path of php.

Changing this behaviour is not a bug, but a feature request. Note that this is partitially also a BC break and can not be integrated as is without deeper investigation. Additionally your code makes it impossible to use the rename filter to set different directories as it's actually recommended.

Didn't saw that anotation, and in the tutorial in your blog you where using a only filename in the filter, I suppose I didn't read that well, I'll update my code.

Thanks for your fast respone.

Duplicate of ZF-6408

New feature implemented with r16009