1 file_test.module | _file_test_form_submit(&$form, &$form_state) |
Process the upload.
File
- core/
modules/ simpletest/ tests/ file_test.module, line 103 - Helper module for the file tests.
Code
function _file_test_form_submit(&$form, &$form_state) {
// Process the upload and perform validation. Note: we're using the
// form value for the $replace parameter.
if (!empty($form_state['values']['file_subdirectory'])) {
$destination = 'temporary://' . $form_state['values']['file_subdirectory'];
file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
}
else {
$destination = FALSE;
}
// Setup validators.
$validators = array();
if ($form_state['values']['is_image_file']) {
$validators['file_validate_is_image'] = array();
}
$allow = $form_state['values']['allow_all_extensions'];
if ($allow === 'empty_array') {
$validators['file_validate_extensions'] = array();
}
elseif ($allow === 'empty_string') {
$validators['file_validate_extensions'] = array('');
}
elseif (!empty($form_state['values']['extensions'])) {
$validators['file_validate_extensions'] = array($form_state['values']['extensions']);
}
$file = file_save_upload('file_test_upload', $validators, $destination, $form_state['values']['file_test_replace']);
if ($file) {
$form_state['values']['file_test_upload'] = $file;
backdrop_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->uri)));
backdrop_set_message(t('File name is @filename.', array('@filename' => $file->filename)));
backdrop_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->filemime)));
backdrop_set_message(t('You WIN!'));
}
elseif ($file === FALSE) {
backdrop_set_message(t('Epic upload FAIL!'), 'error');
}
}