fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

Fuel 1.6 Upload Facade duplicates uploaded files #1426

Closed David-Mueller closed 11 years ago

David-Mueller commented 11 years ago

Post Request Payload: ------WebKitFormBoundaryezAqIWuSA9jSxbUA Content-Disposition: form-data; name="avatar"; filename="IMG_4139.jpg" Content-Type: image/jpeg

...

controller Code:

$config = array(
    'path' => DOCROOT . '/files/users',
    'prefix' => $this->current_user->id . '_',
    'randomize' => true,
    'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
);
Upload::process($config);

// if there are any valid files
if (Upload::is_valid())
{
    // save them according to the config
    Upload::save();

    ...
} 

As a result, I see "2_17ca58b02b927f968e1c610aadf6371e_1.jpg" (empty file) and "2_17ca58b02b927f968e1c610aadf6371e.jpg" (the image).

I found that static::$upload->getAllFiles() returns two identical files.

WanWizard commented 11 years ago

By default, auto processing is on in the configuration. This was already the case in previous versions.

This means that if you call Upload::process() yourself, you're processing the uploaded files twice. In previous versions that was not a problem, as data was stored in arrays and a second run would just overwrite the first one.

The new 2.0 package is object oriented, and creates File objects for every file uploaded. A second run in this case just creates a new set of objects causing this behaviour.

So, if you intend to process manually, make sure auto_process is set to false in your config.

I'll add a new ticket for this on the fuelphp/upload repo to see if we can come up with duplicate file detection.