addString() public method

Add a file to the zip using its contents
public addString ( $filename, $content )
$filename string The name of the file to create
$content string The file contents
Exemplo n.º 1
0
 /**
  * Add a file to the zip using its contents
  *
  * @param $filename string The name of the file to create
  * @param $content string The file contents
  * @return $this Zipper instance
  * @static 
  */
 public static function addString($filename, $content)
 {
     return \Chumper\Zipper\Zipper::addString($filename, $content);
 }
Exemplo n.º 2
0
 public function postExportPdf(Request $request)
 {
     $ids = null;
     if ($request->exists("checkall")) {
         $filter = !is_null($request->input('search')) ? $this->buildSearch() : '';
         $args["params"] = $filter;
         $rows = $this->model->getRows($args);
         foreach ($rows["rows"] as $row) {
             $ids[] = $row->id;
         }
     }
     if (!$ids) {
         $ids = $request->input('ids');
     }
     if (count($ids) > 0) {
         $uid = uniqid();
         $zip = new \Chumper\Zipper\Zipper();
         $zip->make(storage_path() . "/app/tmp/{$uid}/facturas.zip");
         foreach ($ids as $id) {
             $view = $this->getHtmlContent($id);
             $nombreFact = "factura-{$this->data['row']->serfac}-{$this->data['row']->ejefac}-{$this->data['row']->numfac}.pdf";
             $pdfContents = \PDF::loadHTML($view)->setPaper('a4')->setOption('margin-right', 0)->setOption('margin-bottom', 0)->setOption('margin-left', 0)->setOption('margin-top', 0)->output();
             $zip->addString($nombreFact, $pdfContents);
             $this->data['subgrid'] = isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'][0] : array();
         }
         $zip->close();
         $response = \Response::make(file_get_contents(storage_path() . "/app/tmp/{$uid}/facturas.zip"));
         $size = \Storage::drive("local")->size("tmp/{$uid}/facturas.zip");
         \Storage::drive("local")->deleteDirectory("tmp/{$uid}");
         $response->header('Content-Disposition', 'attachment; filename="facturas.zip"');
         $response->header('Content-Length', '$size');
         return $response;
     }
 }