Fileupload element - fatal error

juuser

Well-Known Member
Use Ajax upload = "Yes"
Max files = 1 (so the file data is written in the "main" table, not "repeat" table)

Steps to reproduce:
1) upload a single file and save the form (everything ok so far, file uploaded and saved).
2) delete the file and save the form. File is removed from the server, but the database field is not fully cleared (it will have a "[]" residue. And because of this, form record will not load with the error message:
"count(): Argument #1 ($value) must be of type Countable|array, string given"

Probably the cleanest solution would be something like this in:
\plugins\fabrik_element\fileupload\fileupload.php

Around line 1503, change:
PHP:
         // Only one file
                    $store = array();

                    for ($i = 0; $i < count($files); $i++)
                    {
                        $o         = new stdClass;
                        $o->file   = $files[$i];
                        $o->params = $crop[$files[$i]];
                        $store[]   = $o;
                    }

                    $store = json_encode($store);
                    $formModel->updateFormData($name . '_raw', $store);
                    $formModel->updateFormData($name, $store);

to this:
PHP:
                    // Only one file
                    if( count($files) > 0) {
                        $store = array();

                        for ($i = 0; $i < count($files); $i++)
                        {
                            $o         = new stdClass;
                            $o->file   = $files[$i];
                            $o->params = $crop[$files[$i]];
                            $store[]   = $o;
                        }

                        $store = json_encode($store);
                        $formModel->updateFormData($name . '_raw', $store);
                        $formModel->updateFormData($name, $store);
                    } else {
                        $formModel->updateFormData($name . '_raw', '');
                        $formModel->updateFormData($name, '');                   
                    }

The database field now has empty value instead of "[]" when no file selected. This seems to solve the issue.
 
Back
Top