File Download script in laravel-Zip File creation and download ?Using Laravel
Here i m using the zipper class for creating zip file.Used one controller and viewblade as below Somecontroller.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php public function downloadzipfile(Request $request) { $zipFileClass = new Zipper(); $getDate = date("Ymd"); $getTime = time(); $newFileName = $studentName . '_' . $getDate . '_' . $getTime . '.zip'; $storagePath = public_path() . "/assets/uploads/myzip_files"; $zipFileClass->make($storagePath . $newFileName)->add($downloadinFiles); echo $newFileName; } public function fileDownload(Request $request) { $download_path = $request->input('download_filen_path'); $file_name = $request->input('download_Data'); $headers = array('Content-Type' => 'application/octet-stream'); return response()->download($download_path . "/" . $file_name, $file_name, $headers); } ?> |
someviewblade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
{!! Form::open(array('url' => url('/'fileDownload'), 'name' => 'download_my_zipfile' ,'id'=>'download_my_zipfile')) !!} <input type="hidden" name="download_Data" id="download_Data" /> <input type="hidden" name="download_filen_path" id="download_filen_path" value="{{ public_path() . "/assets/uploads/myzip_files }}" /> {{ Form::close() }} $.ajax({ url: 'downloadzipfile', async: true, type: "POST", data: inputdata, dataType: "html", success: function (data) { $('#download_Data').val(data); $('#download_my_zipfile').submit(); } }); |