title: Symfony2 : How to force download multiple images in one zip file with Ajax
body: <p>This is my AJAX request  :</p>
  
  <pre><code>function DownloadZip() {
  
          var searchIDs = $("#image_id:checked").map(function(){
              return $(this).val();
          }).get(); 
  
          $.ajax(
              {
                  type:'POST',
                  url: $('#admin_product_zip').text(),
                  data: {searchIDs:searchIDs},        
                  success: function(response) {
                  }
              }
          );
          return false;
          }
  </code></pre>
  
  <p>And this is my controller method, I'm getting the product ids and fetch these id's from database, getting the proper images paths :</p>
  
  <pre><code>public function zipMultipleDownload($data){
  
      foreach($data as $product_ind) {
          $product = $this-&gt;repo-&gt;find(3);
          $images=$product-&gt;getColorImagesPaths();
          $itemImages=$product-&gt;getItemImagesPaths();
          $archive_file_name =$product-&gt;getName().$product-&gt;getId().'.zip';
          //print_r($itemImages);
          //return new response('test');
      } 
      $this-&gt;zipFilesAndDownload($images,$archive_file_name,$itemImages);
      //return json_encode($itemImages);
  
  }
  // Function for dowloading images in zip format
  public function zipFilesAndDownload($file_names,$archive_file_name,$itemImages)
  {
      $zip = new ZipArchive();
  
      if ($zip-&gt;open($archive_file_name, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE) === TRUE)
      {
          foreach ($file_names as $files) {
          // $zip-&gt;addFile("uploads/ltf/products/display/web/5232f56d0291a.png","uploads/ltf/products/display/web/5232f56d0291a.png");
              $zip-&gt;addFile($files['web'], $files['web']);
              $zip-&gt;addFile($files['iphone'], $files['iphone']);
          }  
          foreach ($itemImages as $itemfiles) {
              $zip-&gt;addFile($itemfiles['web'],$itemfiles['web']);
              $zip-&gt;addFile($itemfiles['iphone4s'], $itemfiles['iphone4s']);
              $zip-&gt;addFile($itemfiles['iphone5'], $itemfiles['iphone5']);
         }
         $zip-&gt;close();
       }
       else {
           return "can not open";
       }
  
       $response =new Response();
       //then send the headers to foce download the zip file
       $response-&gt;headers-&gt;set('Content-Type','application/zip');
       $response-&gt;headers-&gt;set('Content-Disposition', 'attachment; filename="' . basename($archive_file_name) . '"');        
       $response-&gt;headers-&gt;set('Pragma', "no-cache");
       $response-&gt;headers-&gt;set('Expires', "0");
       $response-&gt;headers-&gt;set('Content-Transfer-Encoding', "binary");
       $response-&gt;sendHeaders();
       $response-&gt;setContent(readfile($archive_file_name));
       return $response;
  }
  </code></pre>
  
  <p>Problem : that's getting binary data, special character not images.<br/>
  Images paths are propers.</p>