function uc_file_files_form_submit in Ubercart 5
File
- uc_file/
uc_file.module, line 770 - Allows products to be associated with downloadable files.
Code
function uc_file_files_form_submit($form_id, $form_values) {
switch ($form_values['step']) {
case 2:
switch ($form_values['action']) {
case 'uc_file_delete':
foreach ($form_values['file_ids'] as $file_id) {
_file_table_action('remove', $file_id, $form_values['recurse_directories'], TRUE);
}
drupal_set_message(t('The select file(s) have been deleted.'));
break;
case 'uc_file_upload':
$dir = variable_get('uc_file_base_dir', NULL) . '/';
$dir = is_null($form_values['upload_dir']) ? $dir : $dir . $form_values['upload_dir'];
if (is_dir($dir)) {
if ($file_object = file_save_upload('upload', FALSE)) {
$temp_file = $file_object->filepath;
copy($file_object->filepath, $dir . basename($file_object->filepath));
$file_object->filepath = $dir . basename($file_object->filepath);
unlink($temp_file);
//Check any if any hook_file_action('upload', $args) are implemented
foreach (module_implements('file_action') as $module) {
$name = $module . '_file_action';
$result = $name('upload', array(
'file_object' => $file_object,
'form_id' => $form_id,
'form_values' => $form_values,
));
}
_file_table_action('insert');
drupal_set_message(t('The %file has been uploaded to %dir', array(
'%file' => basename($file_object->filepath),
'%dir' => $dir,
)));
}
else {
drupal_set_message(t('An error occurred while copying the file to %dir', array(
'%dir' => $dir,
)));
}
}
else {
drupal_set_message(t('Can not move file to %dir', array(
'%dir' => $dir,
)));
}
break;
default:
//Check any if any hook_file_action('validate', $args) are implemented
foreach (module_implements('file_action') as $module) {
$name = $module . '_file_action';
$result = $name('submit', array(
'form_id' => $form_id,
'form_values' => $form_values,
));
}
break;
}
drupal_goto('admin/store/products/files');
break;
default:
break;
}
}