 <pre><code>function handle_form($fields, $POST) { $data = array(); foreach ($fields as $field) { if ($field-&gt;type == "file") do_upload($field-&gt;post); $data[$field-&gt;name] = $POST[$field-&gt;post]; } $this-&gt;db-&gt;insert('table', $data); } </code></pre>