public function handle(Request $request, Closure $next)
 {
     if ($request->getMethod() == 'POST') {
         // Get the max upload size (in Mb, so convert it to bytes)
         $maxUploadSize = 1024 * 1024 * ini_get('post_max_size');
         $contentSize = 0;
         if (isset($_SERVER['HTTP_CONTENT_LENGTH'])) {
             $contentSize = $_SERVER['HTTP_CONTENT_LENGTH'];
         } elseif (isset($_SERVER['CONTENT_LENGTH'])) {
             $contentSize = $_SERVER['CONTENT_LENGTH'];
         }
         if ($contentSize > $maxUploadSize) {
             throw new \Exception('The files uploaded exceed your post_max_size ini directive (limit is ' . ini_get('post_max_size') . ')');
         }
         $uploads = $request->allFiles();
         $this->_uploadErrorCheck($uploads);
     }
     return $next($request);
 }
Example #2
0
 /**
  * Get an array of all of the files on the request.
  *
  * @return array 
  * @static 
  */
 public static function allFiles()
 {
     return \Illuminate\Http\Request::allFiles();
 }
Example #3
0
 public function postJustificar(Request $request)
 {
     $text = $request->razon;
     $tabla = $request->contenido;
     $texto2 = $request->contable;
     $id = $request->id;
     $diff = Diferencias::find($id);
     $contr = $request->contribuyente;
     if ($diff) {
         $diff->solucion = true;
         if (strlen($text) == 0) {
             $diff->solucion = false;
         }
         $diff->obser = $text;
         $diff->aspectos = $tabla;
         $diff->aspectos_texto = $texto2;
         $time = time();
         if ($request->hasFile('anexos')) {
             $anexos = $request->allFiles('anexos')['anexos'];
             $count = 0;
             foreach ($anexos as $anexo) {
                 $rules = array('file' => 'required');
                 //'required|mimes:png,gif,jpeg,txt,pdf,doc'
                 $validator = Validator::make(array('file' => $anexo), $rules);
                 if ($validator->passes()) {
                     $destinationPath = storage_path("anexos/{$contr}");
                     $filenameOrig = $anexo->getClientOriginalName();
                     $filename = "{$id}" . "_" . "{$count}" . "_{$time}" . "_" . $filenameOrig;
                     if (!file_exists($destinationPath)) {
                         File::makeDirectory($destinationPath, $mode = 0777, true, true);
                     }
                     $upload_success = $anexo->move($destinationPath, $filename);
                     Comprobante::create(['file' => "{$destinationPath}/{$filename}", 'diferencia_id' => $id]);
                     $count++;
                 }
             }
         }
         $nombre = session('name');
         $notification = new NotHelper(session('id'), "{$nombre} ha justificado una diferencia para el contribuyente {$contr}", 0, url('cargas'));
         $notification->toMoreLevelThan(session('level'));
         $diff->save();
     }
     Session::flash('message', 'Cambio realizado exitosamente');
     return redirect()->back();
 }
Example #4
0
 /**
  * Upload the file.
  *
  * @param Model   $model
  * @param Request $request
  *
  * @return void
  */
 private function uploadFileTest($model, Request $request)
 {
     // Filter through all the uploaded files, only grabbing the files in our
     // Fillable, (we don't want any extra things)
     $valid_files = collect($request->allFiles())->filter(function ($file, $key) use($model) {
         return in_array($key, $model->getFillable());
     });
     //  For each file process the upload.
     // Of course, if the collection of valid_files is empty, nothing will happen.
     $valid_files->each(function (\Illuminate\Http\UploadedFile $file, $key) use($model) {
         $ext = $file->guessExtension();
         $name = Warden::generateUUID() . '.' . $ext;
         $fs = new Filesystem();
         $fs->makeDirectory($file_path = storage_path('app/uploads'), 0755, true, true);
         $model->{$key} = $name;
         $file->move($file_path, $name);
     });
 }