I am creating a custom module where the user uploads and image to the Drupal DB using a form. All the data except for the file is being put into the DB though. The only thing that shows in the 'image' field is "[BLOB - 0 B]" The only instructions/tutorials that I can find are for uploading files to a directory, not a table in the db.
function new_floor_map_form($form, &$form_state) {
$form['new'] = array(
'#type' => 'markup',
'#markup' => '<h2>'.t('Start a new floor map:').'</h2>',
);
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['file'] = array(
'#type' => 'file',
'#title' => t('Choose a file'),
);
$form ['name'] =array(
'#type' => 'textfield',
'#title' => t('Name:'),
);
$form['active'] = array(
'#type' => 'checkbox',
'#title' => t('Set as current floor map?'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function new_floor_map_form_submit($form,&$form_state) {
if(isset($form['file']) && (!empty($form['name']))){
$insert = db_insert('floor_map_images')
->fields(array (
'image' => $form_state['values']['file'],
'name' => $form_state['values']['name'],
'active' => $form_state['values']['active'],
))
->execute();
}
}