I’m trying to have a simple form with a file upload, but it isn;t working. when I check form_state both in the validate and in the submit callbacks, the file value is missing. also check $_FILES and there’s nothing.
here is the code I’m using in _form:
$form['file'] = array(
'#type' => 'file',
'#title' => 'Photo',
);
this is what i’m doing in submit:
$validators = array();
$file = file_save_upload('file', $validators, '/sites/default/files');
file_set_status($file, FILE_STATUS_PERMANENT);
krumo ($file);
You need specify
$form['#attributes'] = array('enctype' => 'multipart/form-data');apart from your other fields to make it working. See here for details.