Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- form_state) {
- $form = array(
- '#attributes' => array('enctype' => "multipart/form-data"),
- );
- $form['file'] = array(
- '#type' => 'file',
- '#title' => t('Public Notice'),
- '#description' => t('any PDFs that you upload here will be added to the front page under PUBLIC NOTICES and will also be added to the PUBLIC NOTICE ARCHIVE under NEWS & MEDIA'),
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
- return $form;
- }
- function public_notice_validate($form, &$form_state) {
- $file = file_save_upload('file', array(
- 'file_validate_extensions' => array('pdf xls html doc txt')), $upload_destination);
- $upload_destination = 'sites/default/files/news';
- // If the file passed validation:
- if (isset($file->filename)) {
- // if (file_move($file, $file->filename)) {
- // if (file_move($file, variable_get($upload_destination, "sites/default/files/test" . current($doctype)), $file->filename)){
- if (file_move($file, $upload_destination, $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.
- $form_state['storage']['file'] = $file;
- }
- else {
- form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
- }
- }
- else {
- form_set_error('file', t('Invalid file, only images with the extension pdf xls html doc txt are allowed'));
- }
- }
- function public_notice_submit($form, &$form_state) {
- $file = $form_state['storage']['file'];
- // We are done with the file, remove it from storage.
- unset($form_state['storage']['file']);
- // Make the storage of the file permanent
- file_set_status($file, FILE_STATUS_PERMANENT);
- // Set a response to the user.
- drupal_set_message(t('@filename has been uploaded.', array('@filename' => $file->filename)));
- // drupal_set_message('to: %destination ' , array('%destination' => $upload_destination));
Add Comment
Please, Sign In to add comment