I'd like to know if it is possible to have Craft unzip a .zip file that authenticated users have uploaded through the CP. The idea is that the users will prepare several static html, javascript, css and image files -- rather than having them upload them all individually, I'd like to let them zip them, and upload a single file instead, and then use Craft to unzip them in place them in an appropriate spot. I've got the upload figured out - I'm just not sure how to move ahead with the unzip, or if it's even possible.


I'm 99% sure the answer is yes, that's doable, although you'd need a custom plugin to handle the bulk of it. You'd need to write some PHP to handle the unzip, and place the files where you want them.

You may want to create a plugin with a Controller to handle the file upload & unzip. You can use Craft's Zip::compress() and Zip::unzip() methods to help. Your form will be able to POST directly to that controller.

  • Sorry if this is a dumb question, but how do I have my form POST directly to the controller from within the CP? My intention was to have a CP user upload the .zip file as a field (just one of several fields) within an Entry. Is there a way to do that, or do I need a new approach?
    – Alice G.
    Dec 15 '14 at 20:56
  • Ah, my suggestion assumed that your custom plugin would include a custom form to handle the upload. But that may not be necessary... Check out the onSaveAsset event. That will get triggered every time an asset is uploaded (in a typical fashion), so that would be a good opportunity for you to insert your programming logic. Here's instructions on how to use events...
    – Lindsey D
    Dec 16 '14 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.