<p>I'm 99% sure the answer is <strong>yes, that's doable</strong>, 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.</p>

<p>You may want to create a plugin with a <a href="http://buildwithcraft.com/docs/plugins/controllers" rel="nofollow">Controller</a> to handle the file upload &amp; unzip.  You can use Craft's <a href="http://buildwithcraft.com/classreference/etc/io/Zip#compress-detail" rel="nofollow">Zip::compress()</a> and <a href="http://buildwithcraft.com/classreference/etc/io/Zip#unzip-detail" rel="nofollow">Zip::unzip()</a> methods to help. Your form will be able to POST directly to that controller.</p>

CC BY-SA 3.0
2014-12-15T20:56:31.377Z
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.
CC BY-SA 3.0
2014-12-16T06:39:18.087Z
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](http://buildwithcraft.com/docs/plugins/events-reference#assets-onSaveAsset). 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...](http://buildwithcraft.com/docs/plugins/hooks-and-events#listening-for-events)
Lindsey D
CC BY-SA 3.0
2014-12-13T00:14:57.757Z
2014-12-14T00:46:28.303Z
2014-12-14T00:46:28.303Z
Lindsey D
<p>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.</p>

<assets><upload>
Unzip zipped file after upload
# Unzip zipped file after upload

(Asked by: username_0 on 2014-12-12)

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.

**Tags:** assets, upload

---

## 1 answers

### Answer by username_1 on 2014-12-13. Score: 3

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](http://buildwithcraft.com/docs/plugins/controllers) to handle the file upload & unzip. You can use Craft's [Zip::compress()](http://buildwithcraft.com/classreference/etc/io/Zip#compress-detail) and [Zip::unzip()](http://buildwithcraft.com/classreference/etc/io/Zip#unzip-detail) methods to help. Your form will be able to POST directly to that controller.

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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](http://buildwithcraft.com/docs/plugins/events-reference#assets-onSaveAsset). 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...](http://buildwithcraft.com/docs/plugins/hooks-and-events#listening-for-events)  

---

