Download Multiple Files with Kohana 3.1 Zip Library

Posted (Updated ) in PHP

While aimlessly browsing my Twitter feed last night, I came across this tutorial on using CodeIgniter‘s Zip class. Kohana 3.1 doesn’t seem to come with similar functionality out of the box (at least from the brief glance I took), so I figured I’d write up a quick patch to get CI’s class working with it.

Download the module with example controller and test files here.

You can read up on how to use the class in CodeIgniter’s documentation or the tutorial linked to above. I’ve included a controller and 2 test files in the download above as a kind of ‘quick start guide’. To access them simply go to /koziptest and /koziptest/invalid for a successful and unsuccessful download respectively.

There isn’t really any more to say about this one other than the fact that I made the methods in my module chainable for convenience and consistency with other Kohana classes. Note that this means the read_file, read_dir and archive methods will now throw exceptions if you use an invalid file/directory path or your input or output files aren’t readable/writable – so remember to use a try..catch block! I’ve also made the download method take a Request variable as its first argument – simply pass your controllers current request to it like so:

$Zip->download( $this->response )
  • Chuck

    Have you taken a look at Yii? It’s by far my favorite PHP framework. I tried CI but Yii was just what I needed. It gave me a lot of power that I was used to with Ruby on Rails which I miss a lot when when dealing with PHP

    • Flynsarmy

      Sounds like someone’s trying to boost Yii’s Google search ranking with a shameless plug 🙂

      • Chuck

        Ha to be honest I haven’t used it in about a
        year, but since I saw you mention Kohana I
        figured I’d bring it up since they’re usually
        compared against each other. Currently I’m
        working on an ecommerce project but don’t want to
        build it from scratch so once again I’m putting
        off using Yii…still trying to decide between
        OpenCart and Magento. Magento
        is fancy but is a beast to extend.

        • Flynsarmy

          If you’re doing anything e-commerce related the ONLY way to go is LemonStand. It’s not free but once you get past that setup cost life is so damn easy. Not only does it pack quite a punch feature-wise out the box but it’s also extremely easy to extend – in fact I started working on modules for it 2 weeks ago and I’ve already completed 2 with a third hopefully done tomorrow. I’d definitely recommend looking into it if it’s not too late!

          PS. Fixed the indenting on nested comments. Much better 🙂

          • Chuck

            Thanks for the info! I’ll definitely check that out. Haha ya the comment input box ran off the screen so I kept hitting return so I could see what I was writing. I actually found your site while searching for Doctrine and WordPress integration. I have a project coming up and figured and ORM would make things easier. So I’ll hopefully be implementing your integration technique.