Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload error

  • Hi,

    I upgraded from 1.5.4 to 1.6 and now I have a problem uploading a file. The file is saving two times.



    To trace the error I used the Debug::dump() in the $_FILES and in the Upload::get_files(). Take a look to the result:



    My code:


    private function create_thumb($id)
    {
    Debug::dump($_FILES);
    $config = array(
    'path' => THUMBS,
    'normalize' => true,
    'ext_whitelist' => array('jpg', 'jpeg'),
    'change_case' => 'lower',
    );

    Upload::process($config);

    Debug::dump(Upload::get_files());

    die();

    if (Upload::is_valid())
    {
    Upload::save(0);

    $file = Upload::get_files(0);

    Image::load(THUMBS.$file['saved_as'], false, $file['extension'])
    ->crop_resize(300, 200)
    ->save(THUMBS.$file['saved_as']);

    $thumb = Model_Video::find($id);
    $thumb->set(array(
    'thumb' => $file['saved_as'],
    ));
    $thumb->save();
    }
    if(Upload::get_errors(0))
    {
    return Upload::get_errors(0);
    }
    return true;
    }



    The Result:


    FIRST DEBUG



    APPPATH/classes/controller/videos.php @ line: 488
    Variable #1:
    (Array, 1 element) ↵
    thumb (Array, 5 elements) ↵
    name (String): "04 - SAT detall.jpg" (19 characters)
    type (String): "image/jpeg" (10 characters)
    tmp_name (String): "/Applications/MAMP/tmp/php/php5iWdzr" (36 characters)
    error (Integer): 0
    size (Integer): 292614


    SECOND DEBUG



    APPPATH/classes/controller/videos.php @ line: 499
    Variable #1:
    (Array, 2 elements) ↵
    0 (Array, 11 elements) ↵
    field (String): "thumb" (5 characters)
    saved_as : null
    name (String): "04 - SAT detall.jpg" (19 characters)
    type (String): "image/jpeg" (10 characters)
    file (String): "/Applications/MAMP/tmp/php/php5iWdzr" (36 characters)
    error (Boolean): false
    size (Integer): 292614
    extension (String): "jpg" (3 characters)
    basename (String): "04 - SAT detall" (15 characters)
    mimetype (String): "image/jpeg" (10 characters)
    errors (Array, 0 elements)
    1 (Array, 11 elements) ↵
    field (String): "thumb" (5 characters)
    saved_as : null
    name (String): "04 - SAT detall.jpg" (19 characters)
    type (String): "image/jpeg" (10 characters)
    file (String): "/Applications/MAMP/tmp/php/php5iWdzr" (36 characters)
    error (Boolean): false
    size (Integer): 292614
    extension (String): "jpg" (3 characters)
    basename (String): "04 - SAT detall" (15 characters)
    mimetype (String): "image/jpeg" (10 characters)
    errors (Array, 0 elements)




    It's a bug?



    Regards,

  • HarroHarro
    Accepted Answer
    No, this happens because of a bug that was "fixed". You're calling process() twice.

    With the old, array based code, the second run would just overwrite everything created in the first one. The new code is object based, and will create a new object for every file uploaded.

    So, either do not call process() manually (not needed unless you want to call it with custom parameters), or disable 'auto_process' in the configuration if you need to.

Howdy, Stranger!

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

In this Discussion