Guest User

Untitled

a guest
Jul 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2. /**
  3. * Implements hook_form_alter().
  4. */
  5. function filetest_form_alter(&$form, &$form_state, $form_id) {
  6. switch ($form_id) {
  7. case 'contact_mail_page':
  8. // Need to set the enctype so the form will allow file uploads
  9. $form['#attributes']['enctype'] = "multipart/form-data";
  10. $form['new_file'] = array(
  11. '#type' => 'file',
  12. '#title' => t('New File'),
  13. '#description' => t('Select the file you want to attach.'),
  14. );
  15. $form['#submit'][] = 'filetest_submit';
  16. break;
  17. }
  18. }
  19.  
  20. function filetest_submit($form, &$form_state) {
  21. $file = file_save_upload('new_file', array(), file_directory_path());
  22. // Print data so we can see what we've got
  23. //var_dump($file);
  24. //die();
  25.  
  26. // Some of the values available from the $file object:
  27. $file_name = $file->filename; // "Letter.pdf"
  28. $file_path = $file->filepath; // "sites/default/files/Letter.pdf"
  29. $file_mime = $file->filemime; // "application/pdf"
  30. $file_size = $file->filesize; // "28711"
  31. $file_timestamp = $file->timestamp; // 1295668507
  32. $fid = $file->fid; // "15"
  33. }
Add Comment
Please, Sign In to add comment