首页 文章

Laravel 5.3从文件导入CSV而不上传

提问于
浏览
0

我使用Maatwebsite / Excel导入CSV文件 . 我的代码看起来像这个教程:http://itsolutionstuff.com/post/laravel-5-import-export-to-excel-and-csv-using-maatwebsite-exampleexample.html我marged这两个函数和我的脚本获取文件并返回文件/

但尽管经过多次尝试,我仍然无法跳过上传文件 . 这意味着,我在特殊文件夹中有CSV文件,我想让这个文件处理数据,而不上传 . 它会自动获取文件(可能是file_get_contents?),并将其传递给Illuminate \ Support \ Facades \ Input .

3 回答

  • 0

    我找到了解决方案我们可以跳过设置为CSV文件路径的 if (Input::hasFile('import_file')) {$path 变量

  • 2

    You can read your excel file using this code

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

    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);
                }
            }
        }
    }
    

相关问题