file('files'); $contents = $this->unzipFile($import_file->getPathname()); $hash = Str::random(32); nlog($hash); Cache::put( $hash, base64_encode( $contents ), 3600 ); CompanyImport::dispatch(auth()->user()->getCompany(), auth()->user(), $hash, $request->except('files'))->delay(now()->addMinutes(2)); return response()->json(['message' => 'Processing'], 200); } private function unzipFile($file_contents) { $zip = new ZipArchive(); $archive = $zip->open($file_contents); $filename = pathinfo($file_contents, PATHINFO_FILENAME); $zip->extractTo(public_path("storage/backups/{$filename}")); $zip->close(); $file_location = public_path("storage/backups/$filename/backup.json"); if (! file_exists($file_location)) throw new NonExistingMigrationFile('Backup file does not exist, or is corrupted.'); $data = file_get_contents($file_location); unlink($file_contents); unlink($file_location); return $data; } }