Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Download multiple files or images?
Is there any way I could provide a “Download all assets” button for a group of images or file downloads within a certain category without preparing a new zip file every time a file is updated or added to a collection?
TXP Builders – finely-crafted code, design and txp
Offline
Re: Download multiple files or images?
Just thinking aloud here. Does this make sense for an admin plugin outline?
- Initial: create a file entry placeholder(s) to hold the zip file(s).
- Hook into the
file_ui › validate_saveevent/step callback - Detect if currently saved file is assigned to one of a defined array of categories by checking $incoming.
- Retrieve a list of filenames and paths in that / those categories
- Zip on the server with ZipArchive or some other external library. Maybe give it a datestamp in the filename.
- Read filename and filesize from the newly created zip file.
- Update the file entry to match the new filename.
Have I overseen anything? I’m not sure whether that callback is the right one but the docs list only file_download, file_list and file_deleted. Or is there perhaps a better way?
TXP Builders – finely-crafted code, design and txp
Offline
Re: Download multiple files or images?
It sounds like it might work, but I’d be tempted to approach it differently if you can. Add a new multi edit option to Zip Files and just add a new multi edit handler then do it one go. It’s way easier than faffing with reading and updating a zip, and does away with the placeholder.
The main downside (besides having to have all the files visible on the same page, which may be a problem if you have more than 96 to zip) is you won’t have a filename for the zip itself. You could perhaps set that elsewhere in a pref, or maybe even add a field to the multi edit widget that accepts a name and, if filled in, uses it as the download name, otherwise it uses some default name.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Download multiple files or images?
Is zipping on the fly an option? This would avoid the archive update headache on file add/delete/rename/replace.
Offline