Forums

save image on DB like BLOB

greghph 06 Dec, 2016
hello it is a very nice component
i have 2 problem
1) how can I save an image in BLOB format on mysql database from Basic file field when an user select it?

2) after the user select the image can i display it?

thx
massimo
GreyHead 06 Dec, 2016
Hi massimo,

This came up once before a few years ago - at that time I couldn't get the image to restore from a blob so gave up. It should be possible using PHP + MySQL in a Custom Code action after the Upload Files action.

Why do you need to save it in the database rather than as an image file in a folder?

Bob
greghph 06 Dec, 2016
Hi Greyhead

I am creating a portal for creating labels that interfaces with the bartender software. this software can load a blob image from mysql
where i insert php code after Upload Files action?
in Edit element settings -> Custom function or
in Setup-> before DBSave?
thanks
GreyHead 06 Dec, 2016
Hi greghph,

I would probably do this in two steps. In the On Submit action use:

a. An Upload Files action to get the image info.

b. A DB Save action to save the form data (and the file info if you want to keep a copy on disc).

c. A Custom Code action to get the image data and save that as a blob - you can update the same record using the id that CF will have added to the form data.

d. If necessary, in the same Custom Code action, delete the copy of the file from the server.

Bob
greghph 16 Dec, 2016
Hi bob
i try but i can't retrieve the image vaues in the custom code
see the screen stamp
GreyHead 16 Dec, 2016
Hi greghph,

You'd need to add the image info to the $form->data array for that to work I think; CF has the file path in the $form->files array.

Bob
greghph 05 Jan, 2017
Hi Bob
and happy new year
i try to do the two steps but i don't know how to retrive the $form->data array for image
i do this
A- action:File Upload
B- action: DBSave (this is the data array and debugger)
Array
(
    [option] => com_chronoforms5
    [chronoform] => insimmagini
    [event] => submit
    [nome] => prova
    [tipo_logo] => varie
    [button6] => Salva
    [percorso] => ririuto.jpg
    [cf_id] => 45
)

Array
(
    [percorso] => Array
        (
            [name] => ririuto.jpg
            [original_name] => ririuto.jpg
            [path] => images\loghi\ririuto.jpg
            [size] => 7104
            [link] => images/loghi/ririuto.jpg
        )
)
Array
(
    [5] => Array
        (
            [Files Upload] => Array
                (
                    [0] => Upload routine started for file upload by : percorso
                    [1] => images\loghi\ririuto.jpg has been uploaded successfully.
                )

        )

    [18] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `j35_immagini` (`nome`, `tipo_logo`, `user_id`, `uniq_id`, `created`) values ('prova', 'varie', '0', 'a6b93b6196a3a5ee3970415a68503b58d1d4781f', '2017-01-05 08:31:35');
                        )
                )
        )
)

how can i retrive this information in the custom code?
[percorso][size]
[percorso[path]
[cf_id]
to change after the record?
thx
GreyHead 05 Jan, 2017
Hi greghph,

The file info is available in $form->files e.g. $form->files['percorso']['size']

The cf_id is available as $form->data['cf_id'] but only after the DB Save action.

Bob
greghph 05 Jan, 2017
Hi Bob
thanks very much
but why i can't update the db after DBsave in custom code?
i write this...example for update field size
<?php
//recupero dati che mi servono
$size=$form->files['percorso']['size'];
//$path=$form->files['percorso']['path'];
$ID=$form->data['cf_id'];
// NELLA VARIABILE $data IL CONTENUTO DEL FILE
//$data = addslashes(fread(fopen($form->files['percorso']['original_name'], 'rb'), $form->files['percorso']['size']));
//Update Tabella
$db = JFactory::getDBO();
$query="UPDATE `j35_immagini` SET `size`=" . $size . " WHERE `cf_id`=" . $ID;

$db->setQuery($query);


?>
greghph 05 Jan, 2017
hi this is the issue
$db = JFactory::getDBO();

$db =& JFactory::getDBO();
GreyHead 06 Jan, 2017
Hi greghph,

What exactly is the problem?

Bob
This topic is locked and no more replies can be posted.