function comment_upload_process_files in Comment Upload 6
Process file uploads.
_state
Parameters
array $form:
3 calls to comment_upload_process_files()
- comment_upload_comment_form_submit in ./
comment_upload.module - Additional submit handler for the comment form.
- comment_upload_comment_form_validate in ./
comment_upload.module - Submit handler for the preview and attach button.
- comment_upload_js in ./
comment_upload.module - React to the Attach button; update file information on AHAH request.
File
- ./
comment_upload.module, line 511 - Provides file attachment functionality for comments.
Code
function comment_upload_process_files(&$form, &$form_state) {
$limits = _upload_file_limits($GLOBALS['user']);
$validators = array(
'file_validate_extensions' => array(
$limits['extensions'],
),
'file_validate_image_resolution' => array(
$limits['resolution'],
),
'file_validate_size' => array(
$limits['file_size'],
$limits['user_size'],
),
);
// Save new file uploads.
if (user_access('upload files to comments') && ($file = file_save_upload('upload', $validators, file_directory_path()))) {
$file->list = variable_get('upload_list_default', 1);
$file->description = $file->filename;
$file->weight = 0;
$file->remove = 0;
if (!isset($form_state['values']['files'][$file->fid]['filepath'])) {
$form_state['values']['files'][$file->fid] = (array) $file;
$file->new = TRUE;
$form['#comment_upload_storage'][$file->fid] = (array) $file;
}
}
else {
$errors = form_get_errors();
if (!empty($errors)) {
return 0;
}
else {
// If no file has been entered, we have an empty upload element in files.
unset($form_state['values']['files']['upload']);
}
}
if (isset($form_state['values']['files'])) {
foreach ($form_state['values']['files'] as $fid => $file) {
$form_state['values']['files'][$fid]['new'] = !empty($form['#comment_upload_storage'][$fid]['new']) ? TRUE : FALSE;
}
}
// Order the form according to the set file weight values.
if (!empty($form_state['values']['files'])) {
$microweight = 0.001;
foreach ($form_state['values']['files'] as $fid => $file) {
if (is_numeric($fid)) {
$form_state['values']['files'][$fid]['#weight'] = $file['weight'] + $microweight;
$microweight += 0.001;
}
}
uasort($form_state['values']['files'], 'element_sort');
}
}