Problem: Save arrays in database (Image Resizer)

How to save image resizer array data to a database.

Overview

The issue occurs because the image resizer outputs file data as an array, which cannot be directly stored in a database table.
Use a Custom Code action to extract the needed array values into individual form data fields, then ensure your database table has corresponding columns to store each value.

Answered
fi fibernet 24 Nov, 2015
Hallo @all

i have a small (maybe ;-)) Problem:

I want to save the data from the image resizer in the database, because I need this data later. Only I have at the moment no plan who :-(

Can you help me please ?

here is the debugger print:
Array
(
    [file1] => Array
        (
            [name] => 20151124145812_20151021093447_team3.jpg
            [original_name] => 20151021093447_team3.jpg
            [path] => images/uploadfiles/20151124145812_20151021093447_team3.jpg
            [size] => 22632
            [link] => images/uploadfiles/20151124145812_20151021093447_team3.jpg
            [thumb_big] => 20151124145812_20151021093447_team3_big.jpg
            [thumb_med] => 20151124145812_20151021093447_team3_med.jpg
            [thumb_small] => 20151124145812_20151021093447_team3_small.jpg
        )

)



file1 is the variable from Image upload.
Gr GreyHead 24 Nov, 2015
Hi fibernet,

What exactly do you want to save and in what format?

The simplest solution is to add a Custom Code action with code like this
<?php
$form->data['file_data'] = json_encode($form->files);
?>
Then add a file_data column to your table (click Delete Cache in the Forms Manager toolbar after changing the table).

Bob
fi fibernet 24 Nov, 2015
Hi Bob,

thx for the fastest answer. I want only store the values in the database, not the files itself.....e.g.
id......current id
user_id......current user id
thumb_small.......filename for small thumb
etc.
Gr GreyHead 24 Nov, 2015
Answer
Hi fibernet,

My code doesn't save the files, just the file data, To save thumb_small you'd need a column called thumb_small and code like this
<?php
$form->data['thumb_small'] = $form->files['file1']['thumb_small']'
?>
or you could get all the data for this file with
<?php
foreach ( $form->files['file1'] as $k => $v ) {
  $form->data[$k] = $v;
}
?>

Bob
fi fibernet 24 Nov, 2015
Bob :-D you are the Best!!!

Thank you very much
This topic is locked and no more replies can be posted.