Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload::save() saves duplicated files in Fuel 1.6
  • When I post a form with one file upload input and then I do this...

    Upload::process(array(
        "path" => DOCROOT.DS."uploads"
    ));
    if (Upload::is_valid())
        Upload::save();


    ...I get 2 uploaded files: the first one is, for example, file.jpg and it's the correct original file and the second one is file_1.jpg with 0 bytes.

    And the Upload::get_files() array has 2 elements, where the second one is incorrect. Even if both files have the same 'size' value, they're different on the disk.
    Variable #1:
    (Array, 2 elements)
         0 (Array, 12 elements)
             field (String): "archivo" (7 characters)
             saved_as (String): "airevida_thumb.jpg" (18 characters)
             name (String): "airevida_thumb.jpg" (18 characters)
             type (String): "image/jpeg" (10 characters)
             file (String): "C:\Windows\Temp\php1623.tmp" (27 characters)
             error (Boolean): false
             size (Integer): 22175
             extension (String): "jpg" (3 characters)
             basename (String): "airevida_thumb" (14 characters)
             mimetype (String): "image/jpeg" (10 characters)
             saved_to (String): "C:\Users\mikele\Documents\Trabajo\BajoCeroII\root\uploads\" (58 characters)
             errors (Array, 0 elements)
         1 (Array, 12 elements)
             field (String): "archivo" (7 characters)
             saved_as (String): "airevida_thumb_1.jpg" (20 characters)
             name (String): "airevida_thumb.jpg" (18 characters)
             type (String): "image/jpeg" (10 characters)
             file (String): "C:\Windows\Temp\php1623.tmp" (27 characters)
             error (Boolean): false
             size (Integer): 22175
             extension (String): "jpg" (3 characters)
             basename (String): "airevida_thumb" (14 characters)
             mimetype (String): "image/jpeg" (10 characters)
             saved_to (String): "C:\Users\mikele\Documents\Trabajo\BajoCeroII\root\uploads\" (58 characters)
             errors (Array, 0 elements)
    This started to happen when I upgraded to v1.6, with v1.5.3 everything was fine. I'm using Apache 2.4.2 and PHP 5.4.13 under Win7 32bits.

    I'm almost sure that this is a bug, what do you think?
  • HarroHarro
    Accepted Answer
    Upload in 1.6 has been replaced by the new 2.0 package which has been backported. It's rewritten from scratch. I've never seen this behaviour before.

    I've looked in the code, but I can't immidiately see where this can go wrong.

    Do you have "auto_process" enabled in the upload config file? If so, you're processing twice, which might account for the files being listed twice. It is by default (so you don't have to call Upload::process() yourself).

    If not, can you do a Upload::get_files() before the process call, and before the save call, and see it they are duplicate there too?
  • It seems like auto_process was enabled, but not by me. This is my config/upload.php file:

    return array(
        "path" => DOCROOT.DS."uploads",
        "normalize" => true,
        "change_case" => "lower",
    );

    I commented the Upload::save() line and it worked fine like it did with 1.5.3. Then I added "auto_process" => false to my upload config and it worked fine too. I can see in the docs that auto_process defaults to true, but I didn't need to set it to false with 1.5.3. Anyway, problem solved, thank you!

    Edit: I guess that doing Upload::process() more than once did no harm with v1.5.3 but it does with v1.6.
  • HarroHarro
    Accepted Answer
    It's on by default, so if you want it off, you need to override the default in your config file, or you should not call process() yourself.

    Big difference is that in the old 1.x code, data was stored in an array, so if you processed twice, it would just overwrite the entries created in the first call. The 2.0 code uses objects for every file, a second run will create new objects again.

    I'll have to look into it and see how this can be avoided.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion