0
votes

I am using Maatwebsite/Excel to import CSV files. My code looks like this tutorial: http://itsolutionstuff.com/post/laravel-5-import-export-to-excel-and-csv-using-maatwebsite-exampleexample.html I marged both functions and my script gets file and returns file/

But despite many attempts I can't skip uploading file. It means, that I have CSV file in special folder, and I would like to get this file to process data, without uploading. It will automatically get file (maybe file_get_contents ?), and pass it to Illuminate\Support\Facades\Input.

3
Be wary of memory limits. If someone uploads a 250 MB .xlsx file, you’re probably not going to be able to process that without hitting the white screen of death and losing data first.Martin Bean

3 Answers

2
votes

This is the perfect way to import your csv in laravel 5.*

 public function importExcel() {
    if (Input::hasFile('import_file')) {
        $path = Input::file('import_file')->getRealPath();
        $data = Excel::load($path, function($reader) {

                })->get();
        if (!empty($data) && $data->count()) {
            $count = 0;
            foreach ($data as $key => $d) {
                $insert = array();
                $insert['name'] = $value->name;
                $this->user->create($insert);
            }
        }
    }
}
0
votes

You can read your excel file using this code

    // for sheet 1
$excelData = $excel->selectSheetsByIndex(0)->load($yourFilePath)->get();
print_r($excelData);
0
votes

I found solution. We can skip if (Input::hasFile('import_file')) { and $path variable set to our CSV file path