Guest User

Untitled

a guest
Jun 26th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. form_state) {
  2. $form = array(
  3. '#attributes' => array('enctype' => "multipart/form-data"),
  4. );
  5. $form['file'] = array(
  6. '#type' => 'file',
  7. '#title' => t('Public Notice'),
  8. '#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'),
  9. );
  10. $form['submit'] = array(
  11. '#type' => 'submit',
  12. '#value' => t('Submit'),
  13. );
  14. return $form;
  15. }
  16.  
  17. function public_notice_validate($form, &$form_state) {
  18. $file = file_save_upload('file', array(
  19. 'file_validate_extensions' => array('pdf xls html doc txt')), $upload_destination);
  20. $upload_destination = 'sites/default/files/news';
  21. // If the file passed validation:
  22. if (isset($file->filename)) {
  23. // if (file_move($file, $file->filename)) {
  24. // if (file_move($file, variable_get($upload_destination, "sites/default/files/test" . current($doctype)), $file->filename)){
  25. if (file_move($file, $upload_destination, $file->filename)){
  26. // Update the new file location in the database.
  27. drupal_write_record('files', $file, 'fid');
  28. // Save the file for use in the submit handler.
  29. $form_state['storage']['file'] = $file;
  30. }
  31. else {
  32. form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
  33. }
  34. }
  35. else {
  36. form_set_error('file', t('Invalid file, only images with the extension pdf xls html doc txt are allowed'));
  37. }
  38. }
  39.  
  40. function public_notice_submit($form, &$form_state) {
  41. $file = $form_state['storage']['file'];
  42. // We are done with the file, remove it from storage.
  43. unset($form_state['storage']['file']);
  44. // Make the storage of the file permanent
  45. file_set_status($file, FILE_STATUS_PERMANENT);
  46. // Set a response to the user.
  47. drupal_set_message(t('@filename has been uploaded.', array('@filename' => $file->filename)));
  48. // drupal_set_message('to: %destination ' , array('%destination' => $upload_destination));
Add Comment
Please, Sign In to add comment