public function extractTo($file, $destination) { $zipper = new \Chumper\Zipper\Zipper(); $zipper->make($file)->extractTo($destination); unlink($file); return true; }
public function postPdfInvoice() { $data = \Request::get("jsonData"); $data = utf8_encode($data); $facturas = json_decode($data, true); //$view = $this->viewInvoice($facturas[0]); //return $view; /*Generamos ZIP*/ $uid = uniqid(); $zip = new \Chumper\Zipper\Zipper(); $zip->make(storage_path() . "/app/tmp/{$uid}/facturas.zip"); $tmpDir = "/tmp/{$uid}"; $this->tmpDir = storage_path('app') . $tmpDir; /*Insertamos cada factura en el zip*/ foreach ($facturas as $factura) { $view = $this->viewInvoice($factura); $view = str_replace("localhost:8080", "localhost", $view); $pdfContents = \PDF::loadHTML($view)->setPaper('a4')->setOption('margin-right', 0)->setOption('margin-bottom', 0)->setOption('margin-left', 0)->setOption('margin-top', 0)->output(); $nombreFact = "factura-{$factura['id']['serfac']}-{$factura['id']['ejefac']}-{$factura['id']['numfac']}.pdf"; $zip->addString($nombreFact, $pdfContents); $uidPdf = uniqid(); \File::put($this->tmpDir . "/{$uidPdf}.pdf", $pdfContents); $this->invoicesToWebRefresh[$uidPdf] = $factura; } /*$return = $this->refreshWeb(); if($return != "ok") { die($return); }*/ /*Cerramos ZIP, eliminamos temportal y descargamos*/ $zip->close(); $response = \Response::make(file_get_contents(storage_path() . "/app/tmp/{$uid}/facturas.zip")); \Storage::drive("local")->deleteDirectory("tmp/{$uid}"); $response->header('Content-Disposition', 'attachment; filename="facturas.zip"'); $response->header('Content-Length', strlen($response->getOriginalContent())); \File::deleteDirectory(storage_path("app") . "/tmp/{$uid}"); return $response; }
public function createTheme() { if (!$this->READY) { return; } try { $tmp_name = 'theme_' . date('dmYHis'); $this->createHeader($tmp_name); $this->createFooter($tmp_name); $this->createIndex($tmp_name); $this->createStyle($tmp_name); $this->createFunctions($tmp_name); $this->createPage($tmp_name); $theme_files = glob($this->tmp_dir . '/' . $tmp_name . '/*'); $bootstrap_files = glob('themes/' . $this->base_theme_name . '/bootstrap/bootstrap.min.css'); $script_files = glob('themes/' . $this->base_theme_name . '/js/*'); $zipper = new \Chumper\Zipper\Zipper(); $zipper->make($tmp_name . '.zip')->add($theme_files)->add($bootstrap_files)->folder('js')->add($script_files); return $tmp_name . '.zip'; } catch (Exception $ex) { return; } }
public function Awsuploadzipfile($file, $userid) { $zipper = new \Chumper\Zipper\Zipper(); $path = public_path() . '/assets/' . $userid; if (!file_exists($path)) { mkdir($path, 0744); } $zipper->make($file)->extractTo($path); $Model = new stdClass(); static $bucket; static $accesskey; static $secret; $dbdata = DB::table('settings')->first(); $bucket = $dbdata->AWSBucketName; $accesskey = $dbdata->APIKey; $secret = $dbdata->AWSSecretKey; $client = S3Client::factory(array('key' => $accesskey, 'secret' => $secret)); $returndata = $this->ScanDirectory($client, $path, $bucket, $userid); return $returndata; }