Zend Framework

Zend_File_Transfer_Adapter_Http upload failure when using Rename filter

Details

Description

I wanted to have an upload field, which would not overwrite any existing file (if I uploaded two foobar.jpg files, the second one would fail with an error message).

In order to do that, I had following code in 1.7.*:

$element->setLabel('Upload a file')
->addFilter('Rename',
array('overwrite' => false));

Everything worked fine. In 1.8.1, there is a change in Zend_File_Transfer_Adapter_Http at the line 160 and following:

$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]); }

That leads to Zend_Filter_File_Rename::getNewName(), which returns $content['tmp_name'] with no change. After that, back in Zend_File_Transfer_Adapter_Http, a move_uploaded_file is being called, with the same file name in both attributes, leading to a PHP error and upload failure (uploaded file is not copied to the desired destination)

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Web\Upload\php1C3F.tmp' to 'D:\Web\Upload\php1C3F.tmp' in D:\Web\Lib\Zend\File\Transfer\Adapter\Http.php on line 169

Solution to this issue is either remove the rename filter, or add a "target" parameter - which works, but is not usable for my situation. I don't want to change any name, I just want to ensure that existing file won't be rewrited on the server.

Activity

Hide
Thomas Weidner added a comment -

Fixed with r16009

Show
Thomas Weidner added a comment - Fixed with r16009

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: