时间:2021-07-01 10:21:17 帮助过:19人阅读
下面这个控制器里面是一个示例,它的图片是可有可无的,所以是把图片单独分出来处理。现在想改一下,就是图片必须上传,那么可以把图片和文本一起$request->all()么?怎么修改代码?
public function store(ArticleRequest $request)
{
$article = new Article($request->except('image'));
$article -> user_id = Auth::id();
$picture = "";
if(Input::hasFile('image'))
{
$file = Input::file('image');
$filename = $file->getClientOriginalName();
$extension = $file -> getClientOriginalExtension();
$picture = sha1($filename . time()) . '.' . $extension;
}
$article -> picture = $picture;
$article -> save();
if(Input::hasFile('image'))
{
$destinationPath = public_path() . '/images/article/'.$article->id.'/';
Input::file('image')->move($destinationPath, $picture);
}
}
下面是视图:
下面这个控制器里面是一个示例,它的图片是可有可无的,所以是把图片单独分出来处理。现在想改一下,就是图片必须上传,那么可以把图片和文本一起$request->all()么?怎么修改代码?
public function store(ArticleRequest $request)
{
$article = new Article($request->except('image'));
$article -> user_id = Auth::id();
$picture = "";
if(Input::hasFile('image'))
{
$file = Input::file('image');
$filename = $file->getClientOriginalName();
$extension = $file -> getClientOriginalExtension();
$picture = sha1($filename . time()) . '.' . $extension;
}
$article -> picture = $picture;
$article -> save();
if(Input::hasFile('image'))
{
$destinationPath = public_path() . '/images/article/'.$article->id.'/';
Input::file('image')->move($destinationPath, $picture);
}
}
下面是视图:
做异步的上传可好?