_file_test_form_submit

Versions
7
_file_test_form_submit(&$form, &$form_state)

Process the upload.

Code

modules/simpletest/tests/file_test.module, line 76

<?php
function _file_test_form_submit(&$form, &$form_state) {
  // Process the upload and validate that it is an image. Note: we're using the
  // form value for the $replace parameter.
  if (!empty($form_state['values']['file_subdir'])) {
    $destination = 'temporary://' . $form_state['values']['file_subdir'];
    file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
  }
  else {
    $destination = FALSE;
  }
  $file = file_save_upload('file_test_upload', array('file_validate_is_image' => array()), $destination, $form_state['values']['file_test_replace']);
  if ($file) {
    $form_state['values']['file_test_upload'] = $file;
    drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->uri)));
    drupal_set_message(t('You WIN!'));
  }
  elseif ($file === FALSE) {
    drupal_set_message(t('Epic upload FAIL!'), 'error');
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.