konrms
3 months ago
391
4
Laravel

Requesting user where to save exported file

Posted 3 months ago by konrms

Hello everyone.

I use phpWord library for creating MS-Word forms in laravel. The forms are named after several id numbers (e.g. 1021052.doc, 1021053.doc etc). After the forms are created, they are zipped using the Zip library. The zip file is saved inside \laravel\public\ folder as zipped_gr_[current date and time].zip file.

I want each time the code is run and the zip file is created, the user to be asked where to save that zip file (eg desktop). And how can this be done when the laravel project is running on the server over the network?

What I have done:

This is my controller code performing the specific operation:

foreach($regs as $i) 

{

....  //code

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
	try 
		{
			$objWriter->save(storage_path('zipped_gr\.'.$i->id.'_gr.docx'));  

//this saves files inside laravel\storage\zipped_gr folder for each id
			
			continue;
		}  
		catch (Exception $e) 
			{
			}
			
			return response()->download(storage_path('zipped_gr\.'.$i->id.'_gr.docx')); 
			continue;
			
}   //foreach ends here
				
$we = Carbon::now();  
$we = Carbon::createFromFormat('Y-m-d H:i:s', $we)->format('dmYHis');

$zip = Zip::create('zipped_gr_'.$we.'.zip');   
$zip->add('c:\xampp\htdocs\laravel\storage\zipped_gr'); //this saves inside public as 
//	zipped_gr_16072020075926

Thank you a lot!

Please sign in or create an account to participate in this conversation.