Search code examples
phpdownloadzipibm-cloudphp-ziparchive

Create a ZIP in PHP: does class ZipArchive exist on Bluemix?


I’m developing a simple PHP application and I need to download multiple files with a single request, which in this case occurs by clicking a button. I’ve seen several web resources that say the way to do this is to create a zip file that contains the files I want to download. The first two instructions to do this are:

$zip = new ZipArchive();
$zip->open(“zipname.zip”, ZipArchive::CREATE);

But during the execution the first instruction doesn’t work. In the log window, the error that appears is this:

Class 'ZipArchive' not found in /home/vcap/app/htdocs/download.php

I’ve echoed phpinfo() to see if ZipArchive is enabled on Bluemix, but it wasn't found.

If it's possible to do this, then how can I make it work?

Otherwise, is there another way to download multiple files that works on Bluemix?


Solution

  • You have to add the PHP module zip to the options.json file.

    If you don't have the options.json file yet, you can create it under the .bp-config directory in your application root directory.

    The options.json file should have the following format:

    {
        "PHP_EXTENSIONS": [ "zip", "zlib", "pdo" ]
    }
    

    After creating this file push your application again using cf push.