이것은 내 데이터베이스에 파일을 업로드하는 방법이지만 업로드 된 파일 형식이나 형식이 잘못된 경우 예외를 처리 할 수 없습니다.처리 파일 업로드 예외 - Laravel
파일이 업로드되지 않았지만 파일 유형이 유효하지 않거나 표준을 충족하지 않는 경우 예외를 처리 할 수 있습니다.
어떻게해야합니까?
컨트롤러 내가 업로드가
public function import($id, Request $request)
{
$country= Country::all()->where('id',$id)->first();
if($request->file('imported-file'))
{
$path = $request->file('imported-file')->getRealPath();
$data = Excel::load($path, function($reader)
{
})->get();
if(!empty($data) && $data->count())
{
foreach ($data->toArray() as $row)
{
if(!empty($row))
{
$dataArray[] =
[
'name' => $row['name'],
];
}
else {
return redirect('admin')->with('error','File format Error');
}
}
if(!empty($dataArray))
{
$country->teams()->createMany($dataArray);
return redirect('admin')->with('status','Countries successfully added');
}
}
}
else {
return redirect('admin')->with('error','No file was uploaded');
}
}
잘못된 유형은 무엇입니까? –
업로드 파일은 무엇입니까? – kunal
@SapneshNaik, Excel 파일을 업로드합니다. 그래서 사용자가 다른 형식을 업로드 할 때 예외 파일을 처리해야합니다. – pogba