- Posts: 77
COMMUNITY FORUM
SOLVED --- All attachments of an item as zip-file?
- Bam Bam
-
Topic Author
- Offline
- Senior Member
Less
More
8 years 9 months ago - 8 years 9 months ago #156734
by Bam Bam
SOLVED --- All attachments of an item as zip-file? was created by Bam Bam
Hey everybody,
is there a chance to get all attachments of an item in one zip-file when clicking a link (e.g. "download all files")?
I have several items with many attachments and want to afford the user to get all files with a single click.
I know, I could zip all files on my desktop and upload it as attachment. But I'm not the only one who edits the items and sometimes new attachments get inserted.
Any idea?
Thanks
Matthew
is there a chance to get all attachments of an item in one zip-file when clicking a link (e.g. "download all files")?
I have several items with many attachments and want to afford the user to get all files with a single click.
I know, I could zip all files on my desktop and upload it as attachment. But I'm not the only one who edits the items and sometimes new attachments get inserted.
Any idea?
Thanks
Matthew
Last edit: 8 years 9 months ago by Bam Bam.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 9 months ago #156742
by Krikor Boghossian
Replied by Krikor Boghossian on topic All attachments of an item as zip-file?
Hello Matthew,
By default, unfortunately this is not possible.
Although it would be a cool feature.
I think you are looking at a custom PHP solution.
By default, unfortunately this is not possible.
Although it would be a cool feature.
I think you are looking at a custom PHP solution.
Please Log in or Create an account to join the conversation.
- Bam Bam
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 77
8 years 9 months ago #156743
by Bam Bam
Replied by Bam Bam on topic All attachments of an item as zip-file?
Jep. I was into a php solution. I thought anybody had also this problem and maybe a workaround ... ;)
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 9 months ago #156744
by Krikor Boghossian
Replied by Krikor Boghossian on topic All attachments of an item as zip-file?
Please Log in or Create an account to join the conversation.
- Bam Bam
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 77
8 years 9 months ago #156748
by Bam Bam
Replied by Bam Bam on topic All attachments of an item as zip-file?
Nice one. Thanks. I already found a similar solution. In that script the zip is created on the fly. ;)
Now I only need to find out how to implement the attachment-links (variables) into the download.php. So the script can find the needed files. :)
Now I only need to find out how to implement the attachment-links (variables) into the download.php. So the script can find the needed files. :)
Please Log in or Create an account to join the conversation.
- Bam Bam
-
Topic Author
- Offline
- Senior Member
Less
More
- Posts: 77
8 years 9 months ago - 8 years 9 months ago #156750
by Bam Bam
Replied by Bam Bam on topic SOLVED --- All attachments of an item as zip-file?
Got a solution, if anyone is interested:
First I added following code to my item.php:then I made a file called "download.php" and added it to my Override-Folder, following code in it:Now by clicking on the link "download all files" a "save to"-window comes up and you got a zip containing all files from this item.
First I added following code to my item.php:
<?php echo '<a href="templates/PATH TO YOUR K2 TEMPLATE-OVERRIDE/download.php?id='.$_GET['id'] = $this->item->id.'&title='.$_GET['title'] = $this->item->title.'" class="btn btn-default">download all files</a>'; ?>
<?php
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../../../../' ));
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
$mainframe = JFactory::getApplication('site');
$id = $_GET['id'];
$title = $_GET['title'];
?>
<?php //database query to get the correct files
$db_att=JFactory::getDBO();
$db_att->setQuery("SELECT `filename`, `titleAttribute`, `itemID` FROM #__k2_attachments WHERE `itemID`= '{$id}' GROUP BY `titleAttribute`");
$att_arr = $db_att->loadObjectList();
?>
<?php
// Prepare File
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::CREATE);
// Stuff with content
foreach ($att_arr as $att_arrr) {
$zip->addFile('../../../../../../media/k2/attachments/'.$att_arrr->filename, $title.'/'.$att_arrr->filename);
}
// Close and send to users
$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="'.$title.'.zip"');
readfile($file);
unlink($file);
?>
Last edit: 8 years 9 months ago by Bam Bam.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 9 months ago #156759
by Krikor Boghossian
Replied by Krikor Boghossian on topic SOLVED --- All attachments of an item as zip-file?
Nice one.
Kudos Mathew :)
Kudos Mathew :)
Please Log in or Create an account to join the conversation.