- <pre name="code" class="php">
-
-
-
-
- public function importexambank(Request $request)
- {
-
-
-
- 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];
-
-
- $results = $reader->get()->toArray();
-
- foreach ($results[0] as $val) {
-
- //进行数据操作
-
- }
-
- });
-
- return redirect('/manage/exam');
-
- }
posted @
2016-11-28 15:43
wepe
阅读(
273)
评论()
编辑
收藏
举报