Hi everyone! In my Laravel application I have a upload function for an Excel file. I got this code from the web and adjusted it to my application. The problem is, it doesn't catch a fatal error exception which is produced when the user submits a file, but hasn't selected a file. I don't understand why it is not being caught. I will add a part of my controller.
public function upload() { $file = array('thefile' => Input::file('thefile')); $rules = array('excel' => 'excel'); $validator = Validator::make($file, $rules); if ($validator->fails()) { return Redirect::to('UploadExcelFile')->withInput()->withErrors($validator); } else { try{ // FatalErrorException happens in this line! if (Input::file('thefile')->isValid()) { $destinationPath = 'uploads'; $fileName = Input::file('thefile')->getClientOriginalName(); Input::file('thefile')->move($destinationPath, $fileName); Session::flash('success', 'Upload successfully'); $fileNameJSON = exec("python /path/to/script/ExcelToJSON3.py $fileName"); // This returns a full path name of the JSON file that is made... if ($fileNameJSON == null){ return Redirect::to('/dashboard/input'); } else { // Getting the ID from the file that is uploaded try { $jsonDecode = json_decode(file_get_contents($fileNameJSON)); } catch (ErrorException $e){ return Redirect::to('/errorpage')->with(array('status'=> 'ErrorException')); } A lot of code for handling the data entered.... }catch (FatalErrorException $e){ return Redirect::to('/errorpage')->with(array('status'=> 'FatalErrorException')); } } return true; } The error that is given:
FatalErrorException in UploadExcelFileController.php line 35: Call to a member function isValid() on a non-object
So, I don't understand why this code doesn't handle the error exception and how I could fix this!
Symfony\Component\Debug\Exception\FatalErrorExceptionat the top of the class asuse Symfony\Component\Debug\Exception\FatalErrorException?