function download_download in Download 7.2
Same name and namespace in other branches
- 7 download.module \download_download()
1 string reference to 'download_download'
- download_menu in ./
download.module - Implements hook_menu().
File
- ./
download.module, line 250 - Handles module administration and download link
Code
function download_download($bundle, $field_info) {
list($entity_type, $fieldname, $id, $delta) = explode('-', $field_info);
$field_name = 'download';
$files = array();
$entity = array_shift(entity_load($entity_type, array(
$id,
)));
$lib_path = libraries_get_path('pclzip');
if (!is_dir($lib_path)) {
$uri_info = entity_uri($entity_type, $entity);
drupal_goto($uri_info['path']);
}
include $lib_path . '/pclzip.lib.php';
$instances = field_info_instances($entity_type, $bundle);
$filename = $entity_type . '-' . $id . '-' . $delta;
foreach ($instances as $instance) {
$field_info = field_info_field($instance['field_name']);
if ($field_info['type'] == 'download_link' && $instance['field_name'] == $fieldname) {
$field_name = $instance['field_name'];
if (!empty($instance['settings']['filename'])) {
$filename = _download_get_filename($instance['settings']['filename'], $entity, $entity_type);
}
}
}
$fields = $entity->{$field_name}[LANGUAGE_NONE][$delta]['download_fields'];
$fieldnames = array_filter(explode(';', $fields));
foreach ($fieldnames as $fieldname) {
if (isset($entity->{$fieldname})) {
foreach ($entity->{$fieldname} as $field_array) {
foreach ($field_array as $field) {
$files[] = drupal_realpath($field['uri']);
}
}
}
}
$filename = $filename . '.zip';
$tmp_file = file_save_data('', 'temporary://' . $filename);
$tmp_file->status = 0;
$file = file_save($tmp_file);
$archive = new PclZip(drupal_realpath($file->uri));
$archive
->add($files, PCLZIP_OPT_REMOVE_ALL_PATH);
module_invoke_all('download_download', $files, $entity);
header("Content-Type: application/force-download");
header('Content-Description: File Transfer');
header('Content-Disposition: inline; filename=' . $filename);
readfile(drupal_realpath($file->uri));
exit;
}