I found multiple drupal and stackoverflow pages with examples of upload forms, but I wasn't able to get one to work. here I have included all the code I used, sort of parsing together what other people have done. I have included a menu, a form, a submit, and validate function. The upload file doesn't save in the sites --> default --> file folder, and the submit set_message isn't displayed upon submit. Why doesn't this work?
<?php
function upload_example_menu() {
//$items = array();
$items['upload_example'] = array(
'title' => t('Upload'),
'page callback' => 'drupal_get_form',
'page arguments' => array('upload_example_form'),
'description' => t('uploading'),
"access callback" => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function upload_example_form() {
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['upload'] = array('#type' => 'file');
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
function upload_example_form_validate($form, &$form_state) {
if(!file_check_upload('upload')) {
form_set_error('upload', 'File missing for upload.');
}
}
function upload_example_form_submit($form, &$form_state) {
$validators = array();
$file = file_save_upload('upload', $validators, file_directory_path());
file_set_status($file, FILE_STATUS_PERMANENT);
drupal_set_message(t('The form has been submitted.'));
}
?>