My target is to manage the max upload file exception, and show a client side friendly message, but I don´t know where is the best place to controll this. This is my controller method:
public function upload_file()
{
if (!Input::hasFile('file'))
return;
$utils = App::make('utils');
$file = Input::file('file');
$name = Input::get('name');
$size = $file->getSize();
if ($size > FileModel::$max_file_size)
return json_encode(array('success'=>false, 'message'=>sprintf('The file size should be lower than %smb.',FileModel::$max_file_size/1000000)));
$original_file_name = $file->getClientOriginalName();
$destination_directory = "";
$final_file_name = $utils->copy_file_to_location($file);
return json_encode(array('success'=>true, 'file'=>$original_file_name));
}
And this is the utils copy_file_to_location method:
public function copy_file_to_location($file, $destination_directory = "")
{
if (!isset($file))
return;
$file_name = time()."_".$file->getClientOriginalName();
$file->move(app_path().'/storage/files/'.$destination_directory, $file_name);
return $file_name;
}
I don't knwo where to handle the exception that is raised when uploading files that have a grater size than the server max upload file size variable. Where and how should I handle this to show a user friendly message and do not lock the user interface. By the way I'm using ExtJs 4 in the client side. Thanks.
EDIT
I found a related question that helps a lot (it is the same problem), but I need to know where, inside Laravel, should I check this.