public function zipAll() { $files = TFFile::where('state', '=', 'downloaded')->get(); $imageCount = TFFile::where('state', '=', 'downloaded')->where('type', '=', 'image')->count(); $videoCount = TFFile::where('state', '=', 'downloaded')->where('type', '=', 'video')->count(); if ($videoCount == 0 && $imageCount == 0) { Log::info('TFZipper : no file to be zipped.'); return; } $fileLocs = ""; $deleteLocs = []; foreach ($files as $file) { $deleteLocs[] = $file->location; $fileLocs .= ' ' . storage_path('app/' . $file->location); $file->state = 'zipped'; $file->save(); } $zipName = Carbon::now()->toDateString() . '.zip'; $zipLocs = 'zip/' . $zipName; $cmdPass = self::PASSWORD; $cmdTarget = storage_path('app/' . $zipLocs); $cmdLocs = $fileLocs; $cmd = ""; $sys = php_uname('s'); if ($sys == 'Windows NT') { $cmd = $this->rarCmd; } else { if ($sys == 'Linux') { $cmd = $this->zipCmd; } } $cmd = sprintf($cmd, $cmdPass, $cmdTarget, $cmdLocs); if ($sys == 'Windows NT') { $cmd = str_replace("/", "\\", $cmd); } $result = $this->runCmd($cmd); if (false == $result) { return; } $zip = new TFZip(); $zip->state = 'zipped'; $zip->error = ''; $zip->name = $zipName; $zip->date = Carbon::now()->toDateString(); $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB'; $zip->imageSize = $imageCount; $zip->videoSize = $videoCount; $zip->location = $zipLocs; $zip->save(); Storage::delete($deleteLocs); }
protected function deleteZip($id) { $zip = TFZip::find($id); if ($zip != null) { Storage::delete($zip->location); $zip->state = 'deleted'; $zip->save(); } return redirect()->route('zip'); }