ZIP file won't download and acts weird with php
<p>I'm working on a system in laravel to make a zip full of photos and download it afterwards.</p>

<p>I decided i really don't want to use libraries for this(it is necessary), so I must use plain php. my controller code:</p>

<pre><code>public function downloadPictures()
{
    $pictures = Input::get('photos');
    $file_paths = array();

    foreach ($pictures as $picture_id) {
         $path = $this-&gt;photos-&gt;getFilepath($picture_id, 'original');
         array_push($file_paths, $path);
    }

    $zip = new ZipArchive;
    $zip-&gt;open('slike.zip', ZipArchive::CREATE);

    foreach ($file_paths as $file) {
        $content = file_get_contents($file);
        $zip-&gt;addFromString(basename($file), $content);
    }

    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false);
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="'.basename($zip-&gt;filename).'"');

    echo var_dump($zip);
    echo basename($zip-&gt;filename);

    $zip-&gt;close();

    echo var_dump($zip);
    echo basename($zip-&gt;filename);
}
</code></pre>

<p>Now with the first part of the code i can say with 100% confidence that i get the right picture paths(that is above the <code>//if (file_exists($file_paths ... )</code> comment, and i made sure by printing them out and using <code>file_exists</code>)</p>

<p>But then things start getting wonky.</p>

<p>Firstly: when i open the zip the numFiles i tested says there are allready 4 files in it, i have no idea why.</p>

<p>Secondly: when i print the response from this controller function in js frontend(using echo in controller <code>var_dump($zip)</code>) i get the zip file properties.. name+ numFile+4 (+4 for some reason), but when i <code>$zip-&gt;close()</code> i can't access the properites echoed zip properties are empty.</p>

<p>Third: the redirect headers, which i used in both ways: before i closed the $zip and after(currently they are before the closing) are not doing anything.. they should produce a donwload form in a browser, are they not?</p>

<p>If somebody could help me i would be so greatful. I need to do this due sunday and i have been fiddling around this for about 8hrs now.(this is my first time doing this). I have done quite a lot of googling and it works for others. I am on ununtu on nginx, php v5.6 and i installed the php zip extension and i am testing it localy on ubuntu mozilla browser.</p>

<p>UPDATE: It doesn't work in chrome either, so it's not firefoxes problem.</p>