ZF-6258: File upload with rename filter pseudo random failing

Issue Type: Bug Created: 2009-04-10T03:20:30.000+0000 Last Updated: 2009-04-11T00:34:17.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Emil Ivanov (vladev) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

Related issues: Attachments:


Using trunk (via svn:externals).

I noticed a while ago in the svn log that there has been an optimization added to Zend_File_Transfer to avoid moving a file twice when there is a rename filter in place.

But in the rename filter there is a check:

<pre class="highlight">
if (!file_exists($file['source'])) {
    return $value;

What this basically does it that it bails out silently (?) if the file is not there, returning the original given filename. But the problem is that the file is actually NOT there since it hasn't been moved yet (the rename optimization I guess) - so the rename filter returns the original name, instead of the new name, and the file is not renamed. The second time I try to upload the same file it magically works since there is a stale copy of the previous attempt.

Not sure I explained it the best way but I'm quite confused :) Ask, and I will try to provide more feedback, if necessary.


Posted by Thomas Weidner (thomas) on 2009-04-10T04:42:50.000+0000

When "the file is not there", then is has not been transferred from the client to PHP. Because the file check is done on the file within the temporary directory.

No temporary file, means no upload, which means, no new name...

Posted by Emil Ivanov (vladev) on 2009-04-10T05:03:04.000+0000

I knew that explanation would blew up. ;)

The file got to the server - it's in the /tmp dir under the name PHP gave it (something like /tmp/adyU639A) As far as I understand the Zend_File_Transfer component will then move it to the destination (set via setDestination()). Then the rename filter would be applied, moving it yet again to it's last location.

You've introduced a check for the rename filter in the adapter to skip one moving (which is a very good idea).

Let's write the locations where the file ends up in the non-optimized case:

<pre class="highlight">
PHP               Zend_File_Transfer               Rename filter
 /tmp/adyU639A -> /home/me/myapp/upload/car.jpg -> /home/me/myapp/cars/as5d675123

What the rename filter check (based on debuging I did) is for the existence of the second path (.../car.jpg) - which apparently does not exist since the file hasn't beed moved yet by the Zend_FIle_Transfer component.

Here are the places I think the bug can be found:

<pre class="highlight">
if ($rename !== null) {
    $filename = $rename->getNewName($directory . $content['name']);
    $key = array_search('Rename', $this->_files[$file]['filters']);

The path passes to getNewName() is the path in the middle (the example above).

Posted by Thomas Weidner (thomas) on 2009-04-10T08:38:24.000+0000

Fixed with r14818 Problem occured when not giving source

Posted by Emil Ivanov (vladev) on 2009-04-11T00:34:04.000+0000

Awesome! Thank you very much. :)

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.