尝试上传图像时,方法[vlidate]在laravel 5.3中不存在错误

时间:2017-02-27 09:36:50

标签: php laravel-5.3

我正在laravel 5.3中开发一个项目,我必须创建一个1字段表单来更改我的表单的网站徽标。

enter image description here

我不需要在数据库中保存路径。我只需要在\ public \ images \中上传带有name徽标的文件,只允许使用png文件。所以它将是ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; server { listen 443 ssl; server_name www.example.com; return 301 $scheme://example.com$request_uri; } server { listen 443 ssl; server_name example.com; ... }

以下是表单代码。

\public\images\logo.png

这是路线<div class="col-md-8 col-md-offset-2"> @if (count($errors) > 0) <div class="alert alert-danger"> <strong>Whoops!</strong> There were some problems with your input.<br><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif @if ($message = Session::get('success')) <div class="alert alert-success alert-block"> <button type="button" class="close" data-dismiss="alert">×</button> <strong>{{ $message }}</strong> </div> <img src="/images/{{ Session::get('path') }}"> @endif <div class="box box-info"> <div class="box-header with-border text-center"> <h3 class="box-title">Basic Info</h3> </div> <!-- /.box-header --> <!-- form start --> <form class="form-horizontal" action="{{ url('/') }}/admin/change-site-logo" enctype="multipart/form-data" method="POST"> <div class="box-body"> {{ csrf_field() }} <div class="form-group"> <label for="logo" class="col-sm-3 control-label">Logo</label> <div class="col-sm-9"> <input type="file" class="form-control" id="logo" name="logo" placeholder="Logo Image"> </div> </div> <div class="form-group"> <label for="logo" class="col-sm-3 control-label"></label> <div class="col-sm-9"> <img style="width: 200px; height: 50px;" src="https://www.google.com.pk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"> </div> </div> </div> <!-- /.box-body --> <div class="box-footer"> <button type="submit" class="btn btn-info pull-right">Save</button> </div> <!-- /.box-footer --> </form> </div> <br /><br /> </div>

和控制器如下

类adminController扩展Controller {

Route::post('/admin/change-site-logo', 'adminController@logo_change');

我第一次写这种代码所以不知道该修复什么。我只知道错误是public function logo_change(Request $request) { $this->vlidate($request, [ 'logo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', ]); $imageName = 'logo.'.$request->image->getClientOriginalExtension(); $request->image->move(public_path('images'), $imageName); return back() ->with('success', 'Image Uploaded Successfully.') ->with('in path', $imageName); }

0 个答案:

没有答案