我想在导出csv / xls之前计算文件大小(Laravel,Maatwebsite)

In my below code Excel::create function is creating a new csc/xls file and ->download function is downloading the file, I want some function that could calculate file size.

I have searched a lot but couldn't get any solution.

$data = Item::get()->toArray();

return Excel::create('itsolutionstuff_example', function($excel) use ($data) {
    $excel->sheet('mySheet', function($sheet) use ($data)
    {
        $sheet->fromArray($data);
    });
})->download('csv');

You can try to store file locally and serve the file from a path.

In your blade, you can check the filesize of your stored file:

{{ File::size(public_path('path_of_file')) }}

Unfortunate Laravel excel does not provide any API to get the file size before even it is created.

There is a work around you can create a file on the run time you can get the size of the file using file_metadata

 $data = Item::get()->toArray();

 Excel::create('itsolutionstuff_example', function($excel) use ($data) {
    $excel->sheet('mySheet', function($sheet) use ($data){
        $sheet->fromArray($data);
    });
 })->store('filename');

 File::size('filename'); // get file size 

Hope this helps.