diff --git a/components/file.inc b/components/file.inc index bb2bc435..57f17e4a 100644 --- a/components/file.inc +++ b/components/file.inc @@ -23,6 +23,7 @@ function _webform_defaults_file() { ), 'rename' => '', 'scheme' => 'public', + 'temporary_scheme' => FALSE, 'directory' => '', 'progress_indicator' => 'throbber', 'title_display' => 0, @@ -162,12 +163,20 @@ function _webform_edit_file($component) { '#field_prefix' => 'webform/', ); + $form['extra']['temporary_scheme'] = array( + '#type' => 'checkbox', + '#title' => t('Use temporary file system?'), + '#default_value' => $component['extra']['temporary_scheme'], + '#description' => t('Store uploaded files in a temporary location until webform is submitted.'), + '#weight' => 6, + ); + $form['extra']['rename'] = array( '#type' => 'textfield', '#title' => t('Rename files'), '#default_value' => $component['extra']['rename'], '#description' => t('You may optionally use tokens to create a pattern used to rename files upon submission. Omit the extension; it will be added automatically.') . ' ' . theme('webform_token_help', array('groups' => array('node', 'submission'))), - '#weight' => 6, + '#weight' => 7, '#element_validate' => array('_webform_edit_file_rename_validate'), '#access' => webform_variable_get('webform_token_access'), ); @@ -348,6 +357,11 @@ function _webform_render_file($component, $value = NULL, $filter = TRUE, $submis $max_filesize = parse_size($set_filesize); } + // Save the file to the temporary file system. + if (isset($component['extra']['temporary_scheme']) && $component['extra']['temporary_scheme']) { + $component['extra']['scheme'] = 'temporary'; + } + $element = array( '#type' => 'managed_file', '#theme' => 'webform_managed_file', @@ -661,11 +675,20 @@ function webform_file_process_rename($node, $submission, $component, $fid) { $extension = $info['extension']; // Prepare new file name without extension. - $new_file_name = webform_replace_tokens($component['extra']['rename'], $node, $submission, NULL, TRUE); - $new_file_name = trim($new_file_name); - $new_file_name = _webform_transliterate($new_file_name); - $new_file_name = str_replace('/', '_', $new_file_name); - $new_file_name = preg_replace('/[^a-zA-Z0-9_\- ]/', '', $new_file_name); + if ($component['extra']['rename']) { + $new_file_name = webform_replace_tokens($component['extra']['rename'], $node, $submission, NULL, TRUE); + $new_file_name = trim($new_file_name); + $new_file_name = _webform_transliterate($new_file_name); + $new_file_name = str_replace('/', '_', $new_file_name); + $new_file_name = preg_replace('/[^a-zA-Z0-9_\- ]/', '', $new_file_name); + } + + // If file was stored in the temporary file system, move it to it's intended + // destination directory and filename. + elseif (isset($component['extra']['temporary_scheme']) && $component['extra']['temporary_scheme']) { + $new_file_name = substr($file->filename, 0, -(strlen($extension) + 1)); + } + if (strlen($new_file_name)) { // Prepare the new uri with new filename. $destination = "$destination_dir/$new_file_name.$extension"; diff --git a/webform.module b/webform.module index 48a15165..67773490 100644 --- a/webform.module +++ b/webform.module @@ -1324,6 +1324,9 @@ function webform_webform_submission_presave($node, &$submission) { if (strlen($component['extra']['rename'])) { $renameable[$cid][] = $value; } + elseif (isset($component['extra']['temporary_scheme']) && $component['extra']['temporary_scheme']) { + $renameable[$cid][] = $value; + } } $new_fids = array_merge($new_fids, $submission->data[$cid]); }