【发布时间】:2018-04-04 12:13:13
【问题描述】:
我想问一下,如果没有上传文件但他们按下了上传按钮,我该如何输入错误消息。如果 getRealPath 为空,如何输入错误消息?
public function importExcel()
{
if (empty(Input::file('import_file')->getRealPath())) {
return back()->with('success','No file selected');
}
else {
$path = Input::file('import_file')->getRealPath();
$inserts = [];
Excel::load($path,function($reader) use (&$inserts)
{
foreach ($reader->toArray() as $rows){
foreach($rows as $row){
$inserts[] = ['biometrics' => $row['biometrics'], 'first_name' => $row['first_name'], 'last_name' => $row['last_name'], 'date' => $row['date'], 'emp_in' => $row['emp_in'], 'emp_out' => $row['emp_out']];
}
}
});
if (!empty($inserts)) {
DB::table('attendances')->insert($inserts);
return back()->with('success','Inserted Record successfully');
}
return back();
}
}
【问题讨论】:
-
对您的文件进行适当的验证
标签: laravel laravel-5 laravel-5.5