function form_example_tutorial_1($form_state) {
// This is required to upload files.
// enctype="multipart/form-data" required by browsers to handle files.
$form = array(
'#attributes' => array('enctype' => "multipart/form-data"),
);
$form['file'] = array(
'#type' => 'file',
'#title' => t('Document'),
'#description' => t('Upload a file, allowed extensions: pdf xls'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
// Wysiwyg API bridge & IMCE
/**
* Validate handler for form_example_tutorial_11().
* Verify the valid extensions, and verify content is an image also.
*/
function form_example_tutorial_1_validate($form, &$form_state) {
// $file_directory_path = $file_directory_path.'/test';
$file = file_save_upload('file', array(
'file_validate_extensions' => array('pdf xls html doc txt'),
// 'file_validate_is_image' => array(),
));
// If the file passed validation:
if (isset($file->filename)) {
// Move the file, into the Drupal file system
// $newpath = variable_get('file_directory_path');
if (file_move($file, $file->filename)) {
// Update the new file location in the database.
drupal_write_record('files', $file, 'fid');
// Save the file for use in the submit handler.