我想使用此控制器上传:
if(Input::has('status-text'))
{
$text=e(Input::get('status-text'));
$rules = [
'status_text'=>'required|string',
];
$validator = Validator::make($request->all(), $rules);
if(Input::hasFile('status_image_upload'))
{
$rules['status_image_upload'] = 'image';
$validator = Validator::make($request->all(), $rules);
if($validator->fails())
{
$image = $request->file('status_image_upload');
$imageName = str_random(8).'_'.$image->getClientOriginalName();
$image->move('status_images', $imageName);
$userStatus = new Status();
$userStatus -> class_id = $id;
$userStatus -> status_text = $text;
$userStatus -> image_url = $imageName;
$userStatus -> type = 1;
$userStatus -> users_id = Auth::user()->id;
$userStatus -> save();
Flash::success('Your status has been posted');
return redirect(route('class',['class_id'=>$id]));
}
}
我知道这个控制器适用于上传pdf。但我想存储另一个colunm pdf_url
。为什么我可以在我的刀片页面中查看文件和pdf。
答案 0 :(得分:1)
愿这个帮助
不要忘记将'files'=>'true'
添加到表单的标题
{!! Form::open(array('url'=>'', 'method'=>'post', 'files'=>'true')) !!}
然后在控制器中
if ($file = $request->hasFile('image')) {
$file = $request->file('image');
$filename = time() . '.' . $file->getClientOriginalExtension();
$destinationPath = public_path() . '/images/';
$file->move($destinationPath, $filename);
$support->image = $filename;
}
我建议你使用这个包