Exemplo n.º 1
0
 public function fileUpload($field = 'file_document', $name = 'file_name', $exts = [], $data_provider, $path = "")
 {
     $file = Input::file($field);
     $destinationPath = AppConfig::upload_path() . '/' . $path;
     if (!Input::hasFile($field)) {
         return Redirect::back()->withInput()->withErrors($data_provider->errors)->with('alert', 'file field is empty');
     }
     $ext = $file->getClientOriginalExtension();
     if (count($exts) == 0) {
         $exts = ['pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'jpg', 'jpeg', 'png', 'gif', 'svg'];
     }
     if (!in_array(strtolower($ext), $exts)) {
         return Redirect::back()->withInput()->withErrors($data_provider->errors)->with('alert', 'file is not a document format');
     }
     if (!File::exists($destinationPath)) {
         File::makeDirectory($destinationPath);
     }
     $filename = $file->getClientOriginalName();
     $upload_success = $file->move($destinationPath, $filename);
     $data_provider->{$name} = $filename;
     return true;
 }