Check for PHP zip function
Setzler - April 28, 2009 - 19:02
| Project: | Filebrowser |
| Version: | 6.x-2.0-rc9 |
| Component: | Directory Listing Pages |
| Category: | feature request |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | needs review |
Description
The following code assumes zip_open exists, when for many servers it doesn't.
/**
* hook_link() implementation.
*/
function filebrowser_link($type, $node= NULL, $teaser= FALSE) {
if ($node->type == 'dir_listing' && !$teaser) {
$links= array ();
foreach ($node->file_listing as $file) {
if ($file['kind'] == 0) {
$links['file_browser_download_archive']= array (
'href' => 'filebrowser_download/'.$node->nid.$node->relative_path. ($node->relative_path == '/' ? $node->title : basename($node->relative_path)).".zip",
'title' => t("Download files as an Archive")
);
break;
}
}
return $links;
}
}So we don't get a link to download all as a zip, when it isn't possible, please change it to:
/**
* hook_link() implementation.
*/
function filebrowser_link($type, $node= NULL, $teaser= FALSE) {
if ($node->type == 'dir_listing' && !$teaser && function_exists('zip_open')) {
$links= array ();
foreach ($node->file_listing as $file) {
if ($file['kind'] == 0) {
$links['file_browser_download_archive']= array (
'href' => 'filebrowser_download/'.$node->nid.$node->relative_path. ($node->relative_path == '/' ? $node->title : basename($node->relative_path)).".zip",
'title' => t("Download files as an Archive")
);
break;
}
}
return $links;
}
}
#1
Thank you for this. Patch applied in RC10
#2
Automatically closed -- issue fixed for 2 weeks with no activity.
#3
In addition to the link hook, _filebrowser_download_callback either opens the zip file if zip_open exists or displays an error message. Wouldn't it be better to just download the zip file if zip_open doesn't exists?