【问题标题】:What is the function to upload images in Laravel 5.1Laravel 5.1 上传图片的功能是什么
【发布时间】:2015-12-11 16:23:39
【问题描述】:

我想将数据库中的图像上传到特定文件夹中。我研究了很多教程,但没有找到具体的答案。所以请帮助我。我试过$request->file('image')->move($destinationPath, $fileName);,但它不起作用。

【问题讨论】:

  • 发生了什么?你会遇到错误吗?请提供更多背景信息。
  • 这是我的视图代码.....{!! Form::open(array('action' => array('UserController@uploadImage','file'=>true, 'method'=>'post'))) !!} {!! Form::label('file','File') !!} {!! Form::file('image') !!} {!!表单::提交('上传') !!} {!! Form::open() !!} 这是我的控制器........ public function uploadImage(Request $request) { $filename = $request['image']; $destinationPath = '视图/图像';输入::file('photo')->move($destinationPath, $fileName);返回“上传成功”; }

标签: laravel


【解决方案1】:

试试这个:

Input::file('photo')->move($destinationPath, $fileName);

Input::file('photo')->move($destinationPath);

这里, 照片将是您要保存的图片。

$destinationPath:您要存储上传图片的位置

$fileName:您的图片文件名(可选)

您用来上传文件的表单应采用以下格式:

{!! Form::open(array('name'=>'create', 'method'=>'POST', 'files'=>true, 'url'=>'some/path')) !!}

{!! Form::close() !!}

看看,如果这有帮助。 (欲了解更多信息,请参阅here

【讨论】:

  • 这不起作用错误是..'FatalErrorException in UserController.php line 153:' Call to a member function move() on a non-object.....
  • 做 print_r(Input::file('photo'));看看你是否得到了图像对象。
  • 不显示空白没有打印。如果我这样做 dd($file) 然后打印 null
  • 表示图片没有被控制器接收或上传
  • 如果我使用public function uploadImage(Request $request) { dd($request); },则显示图像名称和令牌编号。
猜你喜欢
  • 1970-01-01
  • 2023-02-08
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 1970-01-01
  • 1970-01-01
  • 2021-07-27
  • 2012-04-30
相关资源
最近更新 更多