/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // ajax upload if ($request->ajax()) { // check upload image if (!$request->hasFile('uploadImg')) { // return json data with error message noImgUpload return response()->json(['error' => 'noUploadImg']); } else { if (!$this->checkImage($request->file('uploadImg'))) { // return json data with error message wrongImgType return response()->json(['error' => 'wrongImgType']); } else { if (filesize($request->file('uploadImg')->getPathname()) > 2 * 2 ** 20) { return response()->json(['error' => 'file size is bigger than 2MB']); } } } } else { // check has uploadImg or not if ($request->hasFile('uploadImg')) { // check image content if (!$this->checkImage($request->file('uploadImg'))) { // check fail, redirect back with errors return back()->withInput($request->except('uploadImg'))->withErrors('小搗蛋 大頭貼只能選圖片唷:)'); } } } // pass all check return $next($request); }
public function postWeight($user_id, Request $request) { if ($request->hasFile('avatar')) { $filename = $request->file('avatar')->getClientOriginalName(); $request->file('avatar')->move(public_path() . '/img/avatars', $user_id . '.' . $filename); $user = User::find($user_id); $user->avatar = $user_id . '.' . $filename; $user->save(); return redirect()->back(); } else { $newweight = $request->input('weight'); if (Weight::where('user_id', '=', $user_id)->exists()) { $oldweight = Weight::where('user_id', '=', $user_id)->orderBy('created_at', 'desc')->first(); } $weight = new Weight(); $weight->weight = $newweight; $weight->user_id = $user_id; if (isset($oldweight)) { $weight->difference = $oldweight->weight - $newweight; } else { $weight->difference = 0; } $weight->save(); return redirect()->back()->with('status', 'Weight Saved'); } }
public function create(Request $request) { $destinationPath = public_path('vids/'); $filename = time() . '.' . $request->file('video')->guessExtension(); $request->file('video')->move($destinationPath, $filename); Post::Create(['content' => $filename, 'description' => $request->description, 'category_id' => $request->category_id, 'premium' => $request->premium]); }
protected function handleField(Request $request, $item, array $fields, $groupName, $fieldName) { $modelFolder = $this->slug . DIRECTORY_SEPARATOR; $basePath = base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . config('anavel-crud.uploads_path')); $modelPath = $basePath . $modelFolder; $skip = null; $requestValue = null; if (!empty($fields["{$fieldName}__delete"])) { //We never want to save this field, it doesn't exist in the DB $skip = "{$fieldName}__delete"; //If user wants to delete the existing file if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) { $adapter = new Local($basePath); $filesystem = new Filesystem($adapter); if ($filesystem->has($item->{$fieldName})) { $filesystem->delete($item->{$fieldName}); } $item->setAttribute($fieldName, null); return ['skip' => $skip]; } } if ($request->hasFile($groupName . '.' . $fieldName)) { $fileName = uniqid() . '.' . $request->file($groupName . '.' . $fieldName)->getClientOriginalExtension(); $request->file($groupName . '.' . $fieldName)->move($modelPath, $fileName); $requestValue = $modelFolder . $fileName; } elseif (!empty($request->file($groupName . '.' . $fieldName)) && !$request->file($groupName . '.' . $fieldName)->isValid()) { throw new \Exception($request->file($groupName . '.' . $fieldName)->getErrorMessage()); } return ['requestValue' => $requestValue, 'skip' => $skip]; }
public function update(Request $request, $id) { $params = $request->all(); $freepost = FreePost::find($id); if ($freepost != null) { if ($request->hasFile('coverImage')) { $file = $request->file('coverImage'); $fileName = md5(uniqid()) . '.' . $file->getClientOriginalExtension(); $file->move(base_path() . '/public/upload', $fileName); $params['cover'] = '/upload/' . $fileName; } unset($params['coverImage']); if ($request->hasFile('headImage')) { $file = $request->file('headImage'); $fileName = md5(uniqid()) . '.' . $file->getClientOriginalExtension(); $file->move(base_path() . '/public/upload', $fileName); $params['head_image'] = '/upload/' . $fileName; } unset($params['headImage']); unset($params['_token']); foreach ($params as $n => $p) { $freepost->{$n} = $p; } $freepost->save(); } return redirect()->action('Admin\\FreePostController@show'); }
/** * A model is saving, check for files being uploaded * * @param Illuminate\Database\Eloquent\Model $model * @return void */ public function onSaving(Model $model) { // Check that the model supports uploads through Upchuck if (!$this->supportsUploads($model) || !($map = $model->getUploadMap())) { return; } // Loop through the all of the upload attributes ... foreach ($map as $key => $attribute) { // If there is a file in the input, move the upload to the // config-ed disk and save the resulting URL on the model. if ($this->request->hasFile($key)) { $url = $this->storage->moveUpload($this->request->file($key)); $model->setUploadAttribute($attribute, $url); // Remove the file from the request object after it's been processed. // This prevents other models that may be touched during the processing // of this request (like because of event handlers) from trying to act // on this upload. $this->request->files->remove($key); } // If the attribute field is dirty, delete the old image if ($model->isDirty($attribute) && ($old = $model->getOriginal($attribute))) { $this->storage->delete($old); } } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $fecha = date("Y", strtotime($request->input('fechaNacimiento'))); $y = date("Y"); $resta = $y - $fecha; $validator = Validator::make($request->all(), ['nombre' => 'required', 'apellido' => 'required', 'sexo' => 'required', 'fechaNacimiento' => 'required'], ['required' => 'Ingrese su :attribute.']); if ($validator->fails()) { return redirect()->back()->withErrors($validator->errors()); } else { if ($resta < 10) { return redirect()->back()->withErrors('Es muy pequeño para registrarse'); } else { if ($resta > 75) { return redirect()->back()->withErrors('Es muy grande para registrarse'); } } } $imageName = str_replace(" ", "-", $_COOKIE['usuario']) . "_" . rand(11111, 99999) . '.' . $request->file('avatar')->getClientOriginalExtension(); $request->file('avatar')->move(base_path() . '/public/imagenpersona/', $imageName); $usuario = DB::table('usuario')->where('id', $_COOKIE['id'])->first(); $persona = Persona::find($usuario->personaid); $persona->nombres = $request->input('nombre'); $persona->apellidos = $request->input('apellido'); $persona->fechanacimiento = $request->input('fechaNacimiento'); $persona->ubicacionavatar = $imageName; $persona->sexo = $request->input('sexo'); $persona->save(); return redirect('/'); }
public function store(Request $request) { $user = Auth::user(); if ($user->is('admin|groupadmin')) { if ($request->hasFile('file')) { $filename = $request->file('file')->getClientOriginalName(); if ($request->file('file')->move(sys_get_temp_dir(), $filename)) { $path = sys_get_temp_dir() . '/' . $filename; if ($request->has('user_id')) { $target = User::findOrFail($request->input('user_id')); $folder = $target->username; $ret = redirect(url('admin/show/' . $target->id)); } else { if ($request->has('group_id')) { $group = Group::findOrFail($request->input('group_id')); $folder = $group->name; $ret = redirect(url('admin/groups/')); } } if ($user->testAccess($folder)) { Cloud::loadFile($path, $folder, $filename); } else { abort(403); } unlink($path); } } return $ret; } else { abort(403); } }
/** * Show the form for creating a new resource. * * @return Response */ public function create(Request $request) { // validation $v = \Validator::make($request->all(), ['url_file' => 'required|max:5000', 'place_id' => 'required|numeric', 'type_print' => 'required|numeric']); if ($v->fails()) { return redirect()->back()->withErrors($v->errors())->withInput(); } // generate code print $code = app('App\\Repositories\\PrintList\\PrintListRepository')->_get_code(); $file_name = ""; $old_name_file = ""; // section untuk file if ($request->hasFile('url_file')) { $file_extensi = $request->file('url_file')->getClientOriginalExtension(); $file_name = $code . "." . $file_extensi; $old_name_file = $request->file('url_file')->getClientOriginalName(); if ($file_extensi == "doc" || $file_extensi == "docx" || $file_extensi == "pdf" || $file_extensi == "xls" || $file_extensi == "xlsx" || $file_extensi == "ods" || $file_extensi == "odt") { $request->file('url_file')->move(base_path() . '/public/file', $code . "." . $file_extensi); } else { return redirect()->back()->withErrors('Sorry the file must be with extension doc, docx or pdf'); } } else { return redirect()->back()->withErrors($v->errors())->withInput(); } // saving data app('App\\Repositories\\PrintList\\PrintListRepository')->savePrintList($request->all(), $this->user_id, $code, $file_name, $old_name_file); return redirect('konfirm/' . $code); }
/** * Update the users profile * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = User::find($request->input('user_id')); $user->name = $request->input('name'); $user->email = $request->input('email'); $user->username = $request->input('username'); if ($request->input('password') != '') { $user->password = bcrypt($request->input('password')); } $user->update(); $company = Company::where('user_id', $request->input('user_id'))->first(); $company->name = $request->input('company_name'); $company->description = $request->input('company_description'); $company->phone = $request->input('company_phone'); $company->email = $request->input('company_email'); $company->address1 = $request->input('company_address'); $company->address2 = $request->input('company_address2'); $company->city = $request->input('company_city'); $company->postcode = $request->input('company_postcode'); if ($request->hasFile('logo')) { $file = $request->file('logo'); $name = Str::random(25) . '.' . $file->getClientOriginalExtension(); $image = Image::make($request->file('logo')->getRealPath())->resize(210, 113, function ($constraint) { $constraint->aspectRatio(); }); $image->save(public_path() . '/uploads/' . $name); $company->logo = $name; } $company->update(); flash()->success('Success', 'Profile updated'); return back(); }
public function store(Request $request) { $uniq = md5(uniqid(time(), true)); if (!$request->file('image')) { return Redirect::back(); } if ($request->hasFile('image')) { $image = $request->file('image'); $ext = $image->getClientOriginalExtension(); $name_image = $image->getClientOriginalName(); $image->move('img/temp/', $uniq . '.' . $ext); $image_final = 'img/temp/' . $uniq . '.' . $ext; $int_image = Image::make($image_final); $int_image->resize(568, null, function ($constraint) { $constraint->aspectRatio(); }); $int_image->save($image_final); Session::put('modal', 'true'); } else { $image_final = $request->get('img_bckp'); } Session::put('img', $image_final); Session::put('img_name', $name_image); Session::put('img_hash_name', $uniq . "." . $ext); return Redirect::back(); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(Request $request) { //读取内容 $photo = $request->file('photo'); $extension = strtolower($photo->getClientOriginalExtension()); $input = $request->all(); //save image //get imageurl //save model if ($request->file('photo')->isValid()) { $name = md5(microtime() . $input['name']) . '.' . $extension; $path = 'img/goods'; $request->file('photo')->move($path, $name); $image_url = $path . '/' . $name; $goods = new Goods(); $goods->name = $input['name']; $goods->description = $input['description']; $goods->user_id = Auth::User()->id; $goods->type = $input['type']; $goods->price = $input['price']; $goods->status = 0; $goods->image_url = $image_url; $goods->save(); return redirect('/goods/' . $goods->id . '/detail')->with('message', 'Information successfully recorded'); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $data['arquivo'] = $request->file('file'); $data['extension'] = $request->file('file')->getClientOriginalExtension(); $data['name'] = $request->name; $this->service->createFile($data); }
public function importdata(Request $request) { $results = null; $file = $request->file('exelimport'); $request->file('exelimport')->move(storage_path() . '/public/import/', 'import.xlsx'); $retdate = Excel::load(storage_path('/public/import/import.xlsx'), function ($reader) { $results = $reader->setDateColumns(array('startdate', 'enddate'))->get(); $data = array(); $dataupdate = array(); $datauser = array(); // $results = $reader->get(); $ret = $results->toArray(); $empidtoStatus = "123"; foreach ($ret as $index => $value) { // var_dump($value["enddate"]); $EMP_ID = $value["empid"]; $userinfo = DB::table('TBL_EMPLOYEE_INFO')->where('EMP_ID', $EMP_ID)->get(); $user = DB::table('TBL_USER')->where('EMP_ID', $EMP_ID)->get(); $TBL_EMP_PENSION = DB::table('TBL_EMP_PENSION')->where('EMP_ID', $EMP_ID)->get(); // $StatusID = $value["user_status_id"]; if ($TBL_EMP_PENSION == null) { if ($userinfo == null) { // var_dump($value["enddate"]); $dateS = new Date($value["startdate"]); $dateStart = date("d/m/Y", strtotime($dateS)); $dateE = new Date($value["enddate"]); $dateEnd = date("d/m/Y", strtotime($dateE)); array_push($data, array('EMP_ID' => $value["empid"], 'PREFIX' => $value["prefix"], 'FULL_NAME' => $value["fullname"], 'ENG_NAME' => $value["engname"], 'FIRST_NAME' => $value["firstname"], 'LAST_NAME' => $value["lastname"], 'PRIORITY' => $value["priority"], 'JOB_ID' => $value["jobid"], 'JOB_DESC_SHT' => $value["jobdescsht"], 'JOB_DESC' => $value["jobdesc"], 'PER_ID' => $value["perid"], 'START_DATE' => $dateStart, 'END_DATE' => $dateEnd, 'COST_CENTER' => $value["costcenter"], 'C_LEVEL' => $value["clevel"], 'POST_ID' => $value["posid"], 'POS_DESC' => $value["posdesc"], 'ORG_ID' => $value["orgid"], 'ENG_FIRST_NAME' => $value["engfirstname"], 'ENG_LAST_NAME' => $value["englastname"], 'BIRTH_DATE' => $value["birthdate"], 'ORG_DESC' => $value["orgdesc"], 'PATH_ID' => $value["pathid"], 'DEP_ID' => $value["depid"], 'DIV_ID' => $value["divid"], 'SEC_ID' => $value["secid"], 'PART_ID' => $value["partid"], 'PARTH_SHT' => $value["pathsht"], 'DEP_SHT' => $value["depsht"], 'DIV_SHT' => $value["divsht"], 'SEC_SHT' => $value["secsht"], 'PATH_SHT' => $value["partsht"], 'PARTH_LNG' => $value["pathlng"], 'DEP_LNG' => $value["deplng"], 'DIV_LNG' => $value["divlng"], 'SEC_LNG' => $value["seclng"], 'PART_LNG' => $value["partlng"])); } else { $dateS = new Date($value["startdate"]); $dateStart = date("d/m/Y", strtotime($dateS)); $dateE = new Date($value["enddate"]); $dateEnd = date("d/m/Y", strtotime($dateE)); $dataupdate = array('EMP_ID' => $value["empid"], 'PREFIX' => $value["prefix"], 'FULL_NAME' => $value["fullname"], 'ENG_NAME' => $value["engname"], 'FIRST_NAME' => $value["firstname"], 'LAST_NAME' => $value["lastname"], 'PRIORITY' => $value["priority"], 'JOB_ID' => $value["jobid"], 'JOB_DESC_SHT' => $value["jobdescsht"], 'JOB_DESC' => $value["jobdesc"], 'PER_ID' => $value["perid"], 'START_DATE' => $dateStart, 'END_DATE' => $dateEnd, 'COST_CENTER' => $value["costcenter"], 'C_LEVEL' => $value["clevel"], 'POST_ID' => $value["posid"], 'POS_DESC' => $value["posdesc"], 'ORG_ID' => $value["orgid"], 'ENG_FIRST_NAME' => $value["engfirstname"], 'ENG_LAST_NAME' => $value["englastname"], 'BIRTH_DATE' => $value["birthdate"], 'ORG_DESC' => $value["orgdesc"], 'PATH_ID' => $value["pathid"], 'DEP_ID' => $value["depid"], 'DIV_ID' => $value["divid"], 'SEC_ID' => $value["secid"], 'PART_ID' => $value["partid"], 'PARTH_SHT' => $value["pathsht"], 'DEP_SHT' => $value["depsht"], 'DIV_SHT' => $value["divsht"], 'SEC_SHT' => $value["secsht"], 'PATH_SHT' => $value["partsht"], 'PARTH_LNG' => $value["pathlng"], 'DEP_LNG' => $value["deplng"], 'DIV_LNG' => $value["divlng"], 'SEC_LNG' => $value["seclng"], 'PART_LNG' => $value["partlng"]); DB::table('TBL_EMPLOYEE_INFO')->where('EMP_ID', "=", $value["empid"])->update($dataupdate); } if ($user == null) { $date = new Date(); $pri = $userinfo = DB::table('TBL_PRIVILEGE')->where('USER_PRIVILEGE_ID', 2)->get(); $datedata = $value["birthdate"]; $newDate = substr($datedata, -2) . substr($datedata, -4, 2) . ((int) substr($datedata, -8, 4) + 543); $MEASecEncoe = new \Security(); $ecPass = $MEASecEncoe->encrypt($newDate, "#Gm2014\$06\$30@97"); //$ecPass = exec("cmd /c md5.bat -e ".$newDate." 2>&1"); //$ecPass = explode(':',$ecPass)[1]; $datedefault = new Date("9999-12-31 00:00:00.000"); $admin = 'Administrator'; $user_id = '2'; array_push($datauser, array('EMP_ID' => $EMP_ID, 'USERNAME' => $EMP_ID, 'PASSWORD' => $ecPass, 'PASSWORD_EXPIRE_DATE' => $datedefault, 'CREATE_DATE' => $date, 'CREATE_BY' => $admin, 'LAST_MODIFY_DATE' => $date, 'USER_PRIVILEGE_ID' => $user_id, 'ACCESS_PERMISSIONS' => $pri[0]->ACCESS_PERMISSIONS, 'USER_STATUS_ID' => 13, 'FIRST_LOGIN_FLAG' => 0, 'EMAIL_NOTIFY_FLAG' => 1)); } } $empidtoStatus .= "," . $EMP_ID; } DB::table('TBL_EMPLOYEE_INFO')->insert($data); DB::table('TBL_USER')->insert($datauser); $sql = "UPDATE TBL_USER SET user_status_id= 14 WHERE EMP_ID NOT IN (" . $empidtoStatus . ")"; DB::update(DB::raw($sql)); }); return response()->json(array('success' => true, 'html' => $retdate)); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { //obtenemos el campo file definido en el formulario $file1 = $request->file('foto1'); $file2 = $request->file('foto2'); $file3 = $request->file('foto3'); // $input = array('image' => $file1); // $reglas = array('image' => 'mimes:jpeg,png'); // $validacion = Validator::make($input, $reglas); // if ($validacion->fails()) // { // \Session::flash('flash_message', 'Una de las imagenes no es correcta'); // } //obtenemos el nombre del archivo $nombre1 = $file1->getClientOriginalName(); $nombre2 = $file2->getClientOriginalName(); $nombre3 = $file3->getClientOriginalName(); //indicamos que queremos guardar un nuevo archivo en el disco local \Storage::disk('local')->put($nombre1, \File::get($file1)); \Storage::disk('local')->put($nombre2, \File::get($file2)); \Storage::disk('local')->put($nombre3, \File::get($file3)); $persona = Persona::find($request->persona_id); $persona->fill($request->all()); $persona->foto1 = $request->persona_id . '|' . $nombre1; $persona->foto2 = $request->persona_id . '|' . $nombre2; $persona->foto3 = $request->persona_id . '|' . $nombre3; $persona->save(); return view('new'); }
public function new_post(Request $request) { if ($request->isMethod('post')) { $rules = array('title' => 'required', 'description' => 'required'); $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return Redirect('new_post')->withErrors($validator)->withInput(); } else { $blog = new Blog(); $blog->title = $request->input('title'); $blog->description = $request->input('description'); $blog->category = $request->input('category'); if ($request->hasFile('photo')) { $blog->photo = $request->file('photo')->getClientOriginalName(); $request->file('photo')->move(public_path() . '/user_file/', $blog->photo); } $blog->save(); if ($blog->id) { Session::flash('success_msg', 'You have published new blog successfully'); return redirect('new_post'); } } } $data['categories'] = Category::all(); return view('blog.new_post', $data); }
/** * Store a newly created resource in storage. * * @return Response */ public function postStore(Request $request) { $input = $request->all(); // return ($input['Administrative']); DB::beginTransaction(); $apps = Application::create($input['REGISTRANT']); $input['Administrative']['registrant_id'] = $apps->id; $input['Technical']['registrant_id'] = $apps->id; if ($request->hasFile("image1")) { $destinationPath = 'uploads/a/'; $fileName = time() . "-" . $request->file('image1')->getClientOriginalName(); $request->file('image1')->move($destinationPath, $fileName); $input['Administrative']['image'] = $fileName; } if ($request->hasFile('image2')) { $destinationPath = 'uploads/t/'; $fileName = time() . "-" . $request->file('image2')->getClientOriginalName(); $request->file('image2')->move($destinationPath, $fileName); $input['Technical']['image'] = $fileName; } return 1; Administrative::create($input['Administrative']); Technical::create($input['Technical']); DB::commit(); return redirect()->back()->withSuccess('Application Submitted Successfully'); }
public function postUpload(Request $req) { $response = array(); if ($req->file('excelF')) { $file = $req->file('excelF'); $extension = $file->getClientOriginalExtension(); $filename = $file->getClientOriginalName(); /*periksa extensi file */ if ('xlsx' !== $extension) { $response['code'] = 404; $response['msg'] = "File berextensi {$extension} dengan nama {$filename}, file Seharusnya Berupa Excel"; // $response['msg']="File Anda $file->getClientOriginalName(), Pastikan File yang Anda upload sesuai dengan format "; return $response; // return $response; } elseif (\Storage::disk('local')->put($file->getFilename() . '.' . $extension, \File::get($file))) { // simpan kedadalam table $entry = new Fileentry(); $entry->mime = $file->getClientMimeType(); $entry->original_filename = $file->getClientOriginalName(); $entry->filename = $file->getFilename() . '.' . $extension; $entry->save(); $response['code'] = 200; $response['msg'] = "File {$entry->original_filename} Telah disimpan"; return $response; } } $response['code'] = 404; $response['msg'] = "Gagal Upload File !!!"; return json_encode($response); // echo '{"TEST1": 454535353,"TEST2": "test2"}'; }
public function importdata(Request $request) { $results = null; // $results = $reader->get(); // // $ret = $results->toArray(); $file = $request->file('exelimport'); $request->file('exelimport')->move(storage_path() . '/public/import/', 'import.xlsx'); //$request->file('exelimport') // $results = Excel::load($request->file('exelimport'))->toArray(); $ret = Excel::filter('chunk')->load(storage_path('/public/import/import.xlsx'))->chunk(250, function ($results) { $data = array(); // $results = $reader->toArray(); foreach ($results as $index => $value) { $EMP_ID = $value["emp_id"]; $PERIOD = $value["period"]; // $user = DB::table('TBL_MEMBER_BENEFITS')->where('EMP_ID', $EMP_ID)->where('PERIOD', $PERIOD)->count(); $allquery = "SELECT COUNT(EMP_ID) AS total FROM TBL_MEMBER_BENEFITS WHERE EMP_ID= '" . $EMP_ID . "' AND (PERIOD='" . $PERIOD . "' OR PERIOD IS NULL)"; $all = DB::select(DB::raw($allquery)); $total = $all[0]->total; // array_push($data,'asd','asda'); if ($total == 0) { array_push($data, array('EMP_ID' => $value["emp_id"], 'FULL_NAME' => $value["full_name"], 'PATH_CODE' => $value["path_code"], 'DEP_CODE' => $value["dep_code"], 'DIV_CODE' => $value["div_code"], 'SEC_CODE' => $value["sec_code"], 'PATH_NAME' => $value["path_name"], 'DEP_NAME' => $value["dep_name"], 'DIV_NAME' => $value["div_name"], 'SEC_NAME' => $value["sec_name"], 'HIRE_DATE' => $value["hire_date"], 'END_DATE' => $value["end_date"], 'POSITION_CODE' => $value["position_code"], 'POSITION_NAME' => $value["position_name"], 'JOB_LINE' => $value["job_line"], 'LEVEL_CODE' => $value["level_code"], 'EXE_NAME' => $value["exe_name"], 'EXE1_NAME' => $value["exe1_name"], 'AGE_YEAR' => $value["age_year"], 'AGE_DAY' => $value["age_day"], 'JOB_YEAR' => $value["job_year"], 'JOB_DAY' => $value["job_day"], 'EMPLOYER_CONTRIBUTION_1' => $value["employer_contribution_1"], 'EMPLOYER_EARNING_2' => $value["employer_earning_2"], 'MEMBER_CONTRIBUTION_3' => $value["member_contribution_3"], 'MEMBER_EARNING_4' => $value["member_earning_4"], 'TAX_1' => $value["tax_1"], 'TAX_12' => $value["tax_12"], 'TAX_124' => $value["tax_124"], 'TAX_1234' => $value["tax_1234"], 'GRATUITY' => $value["gratuity"], 'GRATUITY_TAX' => $value["gratuity_tax"], 'RECORD_DATE' => $value["record_date"], 'PERIOD' => $value["period"])); } } // var_dump($data); DB::table('TBL_MEMBER_BENEFITS')->insert($data); //DB::insert(DB::raw($insert)); }); return response()->json(array('success' => true, 'html' => $ret)); }
/** * @param Request $request * @return string */ protected function saveImage(Request $request) { $ext = $request->file('image')->getClientOriginalExtension(); $imageName = str_slug($request->input('name')) . '.' . $ext; $request->file('image')->move('images/products/', $imageName); return $imageName; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $excel = collect(["application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]); $data = $request->except(['_method', '_token']); if (!$request->hasFile('uploadFile')) { return back(); } $mineType = $request->file('uploadFile')->getClientMimeType(); if (!$excel->contains($mineType)) { return back(); } $category = $request->get('category'); $ext = $request->file('uploadFile')->getClientOriginalExtension(); $filename = $category . Carbon::now()->timestamp . "." . $ext; $path = base_path() . "/public/up/"; $dest_file = $path . "/" . $filename; $request->file('uploadFile')->move($path, $filename); switch ($category) { case 'DEPT': $this->importDept($dest_file); break; case 'EMPLOYEE': $this->importEMP($dest_file); break; } return back(); }
public function upload(Request $request) { if ($request->hasFile('file')) { $path = $this->getStorageRoot() . $request->get('directory'); $dir = $request->get('directory'); $filename = $request->get('filename') != '' ? $request->get('filename') : $request->file('file')->getClientOriginalName(); $result = new \stdClass(); $result->name = $filename; $result->directory = $dir; $result->path = '/' . $dir . '/' . $filename; $result->fullPath = \URL::to($dir) . '/' . $filename; $result->backgroundImage = "url('{$result->path}')"; $result->active = false; $request->file('file')->move($path, $filename); // if a model has been assigne dto be updated if ($request->has('model')) { $modelData = json_decode($request->get('model')); $model = new $modelData->modelName(); $model::updateOrCreate(['id' => $modelData->modelId], [$modelData->modelField => $modelData->modelValue]); $result->model = $model; } return response()->json($result); } return response()->json(['No image uploaded']); }
public function post_home(Request $request) { $user = \Auth::user(); if ($request->field == 'email') { $oldemail = $request->data1; $email = $request->data2; User::where('email', $oldemail)->limit(1)->update(['email' => $email]); $user = \Auth::user(); return view('user.index', ['user' => $user, 'message' => 'Updated Email!']); } elseif ($request->field == 'avatar') { $image = $request->data; $name = $user->username; if ($request->file('image')->isValid()) { $request->file('image')->move('users/', $user->username . '.png'); return view('user.index', ['user' => $user, 'message' => 'Updated Avatar!']); } else { return view('user.index', ['user' => $user, 'message' => 'Failed to update Avatar... Please try again in a few minutes.']); } } elseif ($request->field == 'address') { $email = $user->email; User::where('email', $email)->limit(1)->update(['address' => $request->data1, 'city' => $request->data2, 'state' => $request->data3, 'zip' => $request->data4]); return view('user.index', ['user' => $user, 'message' => 'Updated Address!']); } elseif ($request->field == 'phones') { $email = $user->email; User::where('email', $email)->limit(1)->update(['phones' => $request->data1]); return view('user.index', ['user' => $user, 'message' => 'Updated Phone numbers!']); } elseif ($request->field == 'social') { return $request->data; } else { return View('errors.404'); } }
public function uploadpcount(Request $request) { $destinationPath = storage_path() . '/uploads/pcount/'; $fileName = $request->file('data')->getClientOriginalName(); $request->file('data')->move($destinationPath, $fileName); return response()->json(array('msg' => 'file uploaded', 'status' => 0)); }
public function importdata(Request $request) { $results = null; // $results = $reader->get(); // // $ret = $results->toArray(); $file = $request->file('exelimport'); $request->file('exelimport')->move(storage_path() . '/public/import/', 'import.xlsx'); //$request->file('exelimport') // $results = Excel::load($request->file('exelimport'))->toArray(); $ret = Excel::filter('chunk')->load(storage_path('/public/import/import.xlsx'))->chunk(250, function ($results) { $data = array(); // $results = $reader->toArray(); foreach ($results as $index => $value) { // $EMP_ID = $value["emp_id"]; // $PERIOD = $value["period"]; // $user = DB::table('TBL_MEMBER_BENEFITS')->where('EMP_ID', $EMP_ID)->where('PERIOD', $PERIOD)->count(); // $allquery = "SELECT COUNT(EMP_ID) AS total FROM TBL_MEMBER_BENEFITS WHERE EMP_ID= '".$EMP_ID."' AND (PERIOD='".$PERIOD."' OR PERIOD IS NULL)"; // $all = DB::select(DB::raw($allquery)); // $total = $all[0]->total; $date = new Date(); // array_push($data,'asd','asda'); // if ($total == 0) { array_push($data, array('EMP_ID' => $value["emp_id"], 'INVESTMENT_PLAN' => $value["investment_plan"], 'EQUITY' => $value["equity"], 'DEBT' => $value["debt"], 'EQUITY_FUNDS' => $value["equity_funds"], 'BOND_FUNDS' => $value["bond_funds"], 'INVESTMENT_MONEY' => $value["investment_money"], 'REFERENCE_DATE' => $value["reference_date"], 'MEMBER_STATUS' => $value["member_status"], 'CREATE_DATE' => $date)); // } } // var_dump($data); DB::table('TBL_INFORMATION_FROM_ASSET')->insert($data); //DB::insert(DB::raw($insert)); }); return response()->json(array('success' => true, 'html' => $ret)); }
/** * 上传处理控制器 */ public function store(Request $request) { //return $request->file('Filedata')->getClientOriginalExtension(); jpg if ($request->hasFile('Filedata') and $request->file('Filedata')->isValid()) { $allow = array('image/jpeg', 'image/png', 'image/gif'); $mine = $request->file('Filedata')->getMimeType(); if (!in_array($mine, $allow)) { $result['status'] = 0; $result['info'] = '文件类型错误,只能上传图片'; return $result; } //文件大小判断 $max_size = 1024 * 1024 * 3; $size = $request->file('Filedata')->getClientSize(); if ($size > $max_size) { $result['status'] = 0; $result['info'] = '文件大小不能超过3M'; return $result; } //上传文件夹,如果不存在,建立文件夹 $date = date("Y_m"); $path = getcwd() . '/uploads/image/' . $date; if (!is_dir($path)) { mkdir($path); } //生成新文件名 $extension = $request->file('Filedata')->getClientOriginalExtension(); $file_name = md5(time() . rand(0, 9999999)) . '.' . $extension; $request->file('Filedata')->move($path, $file_name); //返回新文件名 $result['status'] = 1; $result['info'] = '/uploads/image/' . $date . '/' . $file_name; return $result; } }
/** * User registration * * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View */ public function register(Request $request) { if ($request->isMethod('post')) { $rules = ['first_name' => 'required', 'last_name' => 'required', 'position' => 'required', 'phone' => 'phone:AM', 'username' => 'required|unique:users,username', 'email' => 'required|email|unique:users,email', 'pass' => 'required|min:6|max:12', 'pass_confirmation' => 'required|min:6|max:12|same:pass', 'image' => 'mimes:jpeg,jpg,png']; Validator::make($request->all(), $rules)->validate(); $user = new User(); $user->first_name = $request->input('first_name'); $user->last_name = $request->input('last_name'); $user->position = $request->input('position'); $user->role_id = 2; if ($request->has('phone')) { $user->phone = $request->input('phone'); } if (!empty($request->file("image"))) { $generated_string = str_random(32); $file = $request->file("image")->store('uploads'); $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension(); Storage::move($file, 'uploads/' . $new_file); $img = Image::make($request->file('image')); $img->crop(200, 200); $img->save(storage_path('app/public/uploads/' . $new_file)); $user->image = $new_file; } $user->username = $request->input('username'); $user->email = $request->input('email'); $user->password = Hash::make($request->input('pass')); $user->activation_token = str_random(32); $user->save(); return redirect('/'); } else { return view('site.auth.register'); } }
public function editUser($id, Request $request) { $user = User::find($id); if ($request->has('first')) { $user->first = $request->input('first'); } if ($request->has('last')) { $user->last = $request->input('last'); } if ($request->has('email')) { $user->email = $request->input('email'); } if ($request->has('phone')) { $user->phone = $request->input('phone'); } if ($request->hasFile('resume')) { $request->file('resume')->move(public_path('resumes'), $user->first . '-' . $user->last . '-' . $user->id . '.jpg'); $user->resume = '/resumes/' . $user->first . '-' . $user->last . '-' . $user->id . '.jpg'; } if ($request->hasFile('headshot')) { $request->file('headshot')->move(public_path('headshots'), $user->first . '-' . $user->last . '-' . $user->id . '.jpg'); $user->headshot = '/headshots/' . $user->first . '-' . $user->last . '-' . $user->id . '.jpg'; } if ($request->has('user_type')) { $user->user_type = $request->input('user_type'); } $request->session()->flash('success', 'User Updated!'); $user->save(); return view('admin.user-edit', ['user' => $user]); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { if ($request->hasFile('preview')) { $date = date('d.m.Y'); //опеределяем текущую дату, она же будет именем каталога для картинок $root = $_SERVER['DOCUMENT_ROOT'] . "/images/"; // это корневая папка для загрузки картинок if (!file_exists($root . $date)) { mkdir($root . $date); } // если папка с датой не существует, то создаем ее $f_name = $request->file('preview')->getClientOriginalName(); //определяем имя файла $request->file('preview')->move($root . $date, $f_name); //перемещаем файл в папку с оригинальным именем $all = $request->all(); //в переменой $all будет массив, который содержит все введенные данные в форме $all['preview'] = "/images/" . $date . "/" . $f_name; // меняем значение preview на нашу ссылку, иначе в базу попадет что-то вроде /tmp/sdfWEsf.tmp ArticleCategory::create($all); //сохраняем массив в базу } else { ArticleCategory::create($request->all()); // если картинка не передана, то сохраняем запрос, как есть. } return back()->with('message', 'Статья добавлена'); // ArticleCategory::create($request->all()); // return back()->with('message','Категория добавлена'); }
public function postIndex(Request $request) { $user = $request->user(); if (UserProfile::where('user_id', $user->id)->count()) { $profile = UserProfile::where('user_id', $user->id)->first(); $profile_picture = $profile->profile_pic; $proof = $profile->photo_id_proof; } else { $profile = new UserProfile(); $profile_picture = NULL; $proof = NULL; } if ($request->hasFile('profile_picture')) { $profile_picture = $user->id . '_' . $request->file('profile_picture')->getClientOriginalName(); $request->file('profile_picture')->move('uploads/profile_pics/', $profile_picture); } if ($request->hasFile('proof')) { $proof = $user->id . '_' . $request->file('proof')->getClientOriginalName(); $request->file('proof')->move('uploads/proof/', $proof); } $profile->user_id = $user->id; $profile->profile_pic = $profile_picture; $profile->designation = $request->designation; $profile->address = $request->address; $profile->city = $request->city; $profile->state = $request->state; $profile->country = $request->country; $profile->photo_id_proof = $proof; $profile->save(); return redirect('profile'); }