Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Implements hook_form_alter().
- */
- function filetest_form_alter(&$form, &$form_state, $form_id) {
- switch ($form_id) {
- case 'contact_mail_page':
- // Need to set the enctype so the form will allow file uploads
- $form['#attributes']['enctype'] = "multipart/form-data";
- $form['new_file'] = array(
- '#type' => 'file',
- '#title' => t('New File'),
- '#description' => t('Select the file you want to attach.'),
- );
- $form['#submit'][] = 'filetest_submit';
- break;
- }
- }
- function filetest_submit($form, &$form_state) {
- $file = file_save_upload('new_file', array(), file_directory_path());
- // Print data so we can see what we've got
- //var_dump($file);
- //die();
- // Some of the values available from the $file object:
- $file_name = $file->filename; // "Letter.pdf"
- $file_path = $file->filepath; // "sites/default/files/Letter.pdf"
- $file_mime = $file->filemime; // "application/pdf"
- $file_size = $file->filesize; // "28711"
- $file_timestamp = $file->timestamp; // 1295668507
- $fid = $file->fid; // "15"
- }
Add Comment
Please, Sign In to add comment