2016-06-11 5 views
0

laravel 용 maatwebsite/excel 패키지를 설치했습니다. 그것은 잘 작동합니다. 내 문제는 내가 파일을 확인한 후 그것을 처리하는 것입니다.Laravel Excel 유효성 확인

내가 포럼을 파일로 보여 어디에서 파일을 업로드하는 것은 여기에있는 업로드() 함수 : 파일이 올바른 형식이있는 경우

public function upload(Request $request) { 

    $orientation = $request->get('orientation'); 
    if($request->file('file')) { 
     $status = Excel::load(Input::file('file'), function ($reader) use ($orientation) { 
      return self::upload_excel_files($reader, $orientation); 
     }); 
     if($status) { 
      Session::flash('status', "Excel data was imported successfully"); 
      return redirect(route('admin.exchange.upload')); 
     } 
     else { 
      return redirect(route('admin.exchange.upload'))->withErrors('Invalid format. Please check the XLS template.'); 
     } 
    } 
    return view('admin.exchange.upload'); 

} 

public function upload_excel_files($file, $orientation) { 
    if(something) return true; 
    else return false; 
} 

upload_excel_files 기능 검사 및 예 그것을 처리하는 경우 성공적인 메모를 반환해야합니다. 파일이 요구 형식과 일치하지 않으면 오류 메시지를 제공해야합니다.

불행히도 나는 사용자 메시지를 어디에 넣어야할지 모르겠다. 예제에서와 같이 항상 성공적인 메시지를 반환합니다. 어떤 이유로 메시지가 upload_excel_files() 함수에있는 경우 첫 번째 리다이렉트에 의해 메시지를받지 못합니다. 이상한 두 번째 리디렉션에서 메시지를받습니다.

내가 뭘 권하고 싶은가? 검사에 대한

답변

0

파일이 올바른 형식 사용 laravel 요청이있는 경우

더 마임 타입

public function rules() 
    { 
     return [ 
      'file' => 'required|mimeTypes:'. 
       'application/vnd.ms-office,'. 
       'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,'. 
       'application/vnd.ms-excel', 
     ]; 
    } 
: https://laravel.com/docs/5.4/validation#working-with-error-messages

: 오류 메시지에 대한 https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

이 글을 읽을