function _uc_file_download in Ubercart 6.2
Same name and namespace in other branches
- 7.3 uc_file/uc_file.pages.inc \_uc_file_download()
Handles file downloading and error states.
Parameters
$fid: The fid of the file specified to download.
$key: The hash key of a user's download.
See also
1 string reference to '_uc_file_download'
- uc_file_menu in uc_file/
uc_file.module - Implements hook_menu().
File
- uc_file/
uc_file.pages.inc, line 151 - File menu items.
Code
function _uc_file_download($fid, $key) {
global $user;
// Error messages for various failed download states.
$admin_message = t('Please contact the site administrator if this message has been received in error.');
$error_messages = array(
UC_FILE_ERROR_NOT_A_FILE => t('The file you requested does not exist. '),
UC_FILE_ERROR_TOO_MANY_BOGUS_REQUESTS => t('You have attempted to download an incorrect file URL too many times. '),
UC_FILE_ERROR_INVALID_DOWNLOAD => t("The following URL is not a valid download link. "),
UC_FILE_ERROR_TOO_MANY_LOCATIONS => t('You have downloaded this file from too many different locations. '),
UC_FILE_ERROR_TOO_MANY_DOWNLOADS => t('You have reached the download limit for this file. '),
UC_FILE_ERROR_EXPIRED => t("This file download has expired. "),
UC_FILE_ERROR_HOOK_ERROR => t("A hook denied your access to this file. "),
);
$ip = ip_address();
$file_download = uc_file_get_by_key($key);
$file_download->full_path = uc_file_qualify_file($file_download->filename);
// If it's ok, we push the file to the user.
$status = _uc_file_download_validate($file_download, $user, $ip);
if ($status == UC_FILE_ERROR_OK) {
_uc_file_download_transfer($file_download, $ip);
}
else {
drupal_set_message($error_messages[$status] . $admin_message, 'error');
}
// Kick 'em to the curb. >:)
_uc_file_download_redirect($user->uid);
}