- <pre name="code" class="php"> /**
- * 导入
- * 保存
- * fyj
- */
- public function importexambank(Request $request)
- {
- // dd($examfilename);
- ini_set('memory_limit', '-1');
- set_time_limit(0);
- //文件名称
- $file = $request->file('examfile');
- $allowed_extensions = ["xls", "xlsx"];
- $extension = $file->getClientOriginalExtension();
- if ($extension && !in_array($extension, $allowed_extensions)) {
- return ['error' => '仅支持格式xls, xlsx.'];
- }
- $dirfile = date('Ymd');
- if (!file_exists('images/uploads/' . $dirfile)) {
- if (!mkdir('images/uploads/' . $dirfile)) {
- return ['error' => '创建目录失败'];
- }
- }
- $destinationPath = "images/uploads/" . $dirfile;
- $filebasename = str_random(10) . mt_rand(10000, 99999);
- $originname = $filebasename . '.' . $extension;
- $file->move($destinationPath, $originname);
- Excel::load('images/uploads/' . $dirfile . '/' . $filebasename . '.' . $extension, function ($reader) {
- $examfile = $_FILES['examfile']['name'];
- $examfilearray = explode('.', $examfile);
- $examfilename = $examfilearray[0];
- // Getting all results
- $results = $reader->get()->toArray();
- foreach ($results[0] as $val) {
- //进行数据操作
- }
- });
- return redirect('/manage/exam');
- }