Issues

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

Issue Type: Improvement Created: 2009-05-28T12:27:30.000+0000 Last Updated: 2009-06-11T13:06:46.000+0000 Status: Resolved Fix version(s): - 1.9.0 (31/Jul/09)

Reporter: Christopher Valderrama (gatorv) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

Related issues: - ZF-6408

Attachments:

Description

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

<pre class="highlight">
                $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:

<pre class="highlight">
                $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

Posted by Thomas Weidner (thomas) on 2009-05-28T12:31:42.000+0000

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

Posted by Christopher Valderrama (gatorv) on 2009-05-28T12:43:59.000+0000

Ok:

<pre class="highlight">
               $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:

<pre class="highlight">
$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.

Posted by Thomas Weidner (thomas) on 2009-05-28T13:20:26.000+0000

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.

Posted by Christopher Valderrama (gatorv) on 2009-05-28T13:28:18.000+0000

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.

Posted by Thomas Weidner (thomas) on 2009-06-11T13:05:06.000+0000

Duplicate of ZF-6408

Posted by Thomas Weidner (thomas) on 2009-06-11T13:06:46.000+0000

New feature implemented with r16009

Have you found an issue?

See the Overview section for more details.

Copyright

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

Contacts