function filebrowser_page_download in Filebrowser 7.2
Same name and namespace in other branches
- 8 filebrowser.pages.inc \filebrowser_page_download()
- 6.2 includes/downloads.inc \filebrowser_page_download()
- 7.4 filebrowser.pages.inc \filebrowser_page_download()
- 7.3 filebrowser.pages.inc \filebrowser_page_download()
Callback for filebrowser_download/%node menu.
1 call to filebrowser_page_download()
- filebrowser_filebrowser_action_process in ./
filebrowser.module - hook_filebrowser_action_process implementation
1 string reference to 'filebrowser_page_download'
File
- ./
filebrowser.pages.inc, line 33 - Several support functions for filebrowser
Code
function filebrowser_page_download($fid) {
$cleanup = NULL;
$files_fid = NULL;
if (strpos($fid, ':')) {
list($fid, $files_fid) = explode(':', $fid);
$files_fid = explode(',', $files_fid);
}
$content = _filebrowser_node_content_load($fid);
$node = NULL;
$target = NULL;
if ($content) {
$node = node_load($content['nid']);
$target = _filebrowser_encoding_to_fs($node, _filebrowser_get_node_root($node) . $content['path']);
}
if (!$content || !$node || !_filebrowser_can_download_file($node) || !$target) {
drupal_access_denied();
exit;
}
if (is_dir($target)) {
if (!function_exists("zip_open")) {
drupal_set_message(t("No ZIP support found in PHP installation, please contact your administrator"));
return;
}
$zip = new ZipArchive();
$target = file_directory_temp() . "/filebrowser_" . _filebrowser_safe_basename($target) . ".zip";
$cleanup = $target;
if (!file_exists(_filebrowser_safe_dirname($target))) {
mkdir(_filebrowser_safe_dirname($target), 0777, TRUE);
}
if (file_exists($target)) {
unlink($target);
}
_filebrowser_load_files($node, $fid);
if ($zip
->open($target, ZIPARCHIVE::CREATE) === TRUE) {
foreach ($node->file_listing as $file_name => $file_data) {
if ($file_data['kind'] === 0 && (!$files_fid || in_array($file_data['fid'], $files_fid))) {
$fs_filename = realpath(_filebrowser_encoding_to_fs($node, _filebrowser_get_node_root($node) . "/" . $file_data['relative-path']));
$zip
->addFile($fs_filename, $file_name);
}
}
$zip
->close();
}
else {
return t("Unable to create temporary zip file '@file'", array(
file => $target,
));
}
}
$decoded_file = _filebrowser_encoding_from_fs($node, $target);
$result = module_invoke_all('filebrowser_download_manager_process', 'private', $target, $decoded_file);
if ($result) {
if ($cleanup && file_exists($cleanup)) {
unlink($cleanup);
}
}
else {
drupal_access_denied();
}
exit;
}