function download_count_export_form_submit in Download Count 6.2
Same name and namespace in other branches
- 7.3 includes/download_count.export.inc \download_count_export_form_submit()
Implementation of hook_submit().
File
- includes/
download_count.export.inc, line 80 - Page callback file for the download_count module export feature.
Code
function download_count_export_form_submit($form, &$form_state) {
variable_set('download_count_export_range', $form_state['values']['download_count_export_range']);
$export_file_path = file_directory_temp() . '/download_count_export_' . ($form_state['values']['download_count_file_info'] == 'all' ? 'all_files' : check_plain($form_state['values']['download_count_file_info']['filename'])) . '_' . date('Y-m-d') . '.csv';
download_count_export_file($export_file_path, $form_state['values']['download_count_export_range'], $form_state['values']['download_count_file_info'], $form_state['values']['download_count_export_date_range_from'], $form_state['values']['download_count_export_date_range_to']);
if (!file_exists($export_file_path)) {
drupal_set_message("{$export_file_path} does not exist.", 'error');
return;
}
if (!($fp = fopen($export_file_path, "r"))) {
drupal_set_message("Could not open {$export_file_path} for reading.", 'error');
return;
}
if (($file_size = filesize($export_file_path)) == 0) {
drupal_set_message("{$export_file_path} is empty.", 'error');
return;
}
drupal_set_header('Content-Disposition: attachment; filename="' . basename($export_file_path) . '"');
drupal_set_header("Content-Length: {$file_size}");
drupal_set_header('Content-Type: application/csv; charset=utf-8');
drupal_set_header('CacheControl: no-cache');
drupal_set_header('Pragma: no-cache');
drupal_set_header('Expires: -1');
flush();
readfile($export_file_path);
unlink($export_file_path);
drupal_set_message(basename($export_file_path) . " has been successfully exported.", 'status');
return;
}