bored

A micro PHP framework
git clone git://git.bitsmanent.org/bored
Log | Files | Refs | README

commit 9b16e28db342d2662fd865ae2d2df4ba1f328692
parent 774dbb608fd4f303b7dda629298fa73c73951bc9
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Wed, 26 Jun 2019 16:36:45 +0200

Handle files related info.

For example, the following HTML:

<input type="file" name="files[]" />
<input type="text" name="files[name][]" value="file 1" />
<input type="text" name="files[caption][]" value="" />

<input type="file" name="files[]" />
<input type="text" name="files[name][]" value="file 2" />
<input type="text" name="files[caption][]" value="caption 2" />

Will be translated into this:

Array
(
    [0] => Array
        (
            [grp] => files
            [info] => Array
                (
                    [name] => file 1
                    [caption] =>
                )

            [name] =>
            [type] =>
            [tmp_name] =>
            [error] => 4
            [size] => 0
        )

    [1] => Array
        (
            [grp] => files
            [info] => Array
                (
                    [name] => file 2
                    [caption] => caption 2
                )

            [name] => filename.extension
            [type] => image/png
            [tmp_name] => /tmp/phpU4TOpb
            [error] => 0
            [size] => 211189
        )

)

Important: info fields *must* be defined for all files otherwise they will not
match driving to data disaster.

This feature is very handy but if you for example forget to put the 1st caption
field, then the text "caption 2" will be inserted into the 1st element of the
array instead of the second. This may be a serious data mismatch so be careful.

Diffstat:
Mbored.php | 4++++
1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/bored.php b/bored.php @@ -448,6 +448,10 @@ function prepare_form() { if(!isset($ret[$t])) { $ret[$t] = []; $ret[$t]["grp"] = $grp; + /* related info */ + $ret[$t]["info"] = []; + foreach((array)@$_POST[$grp] as $ik => $info) + $ret[$t]["info"][$ik] = $info[$t]; } $ret[$t][$k] = $txt; }