我是Laravel 5的新手。实际上我使用的是Laravel Framework 5.1.16版。上传图像时,它会上传并保存在数据库表中,但不会移动到指定的文件夹中。
任何帮助都将不胜感激。
这是我的控制器代码:
public function addexpense(Request $request) {
$inputs=Input::all();
$validation = Validator::make($inputs, Expense::$rules);
if($validation->fails()) {
return Redirect::to('expenseaddform')->withErrors($validation)->withInput();
}else{
$input=Input::only('id','expense_date','expense_category_id','vendor_id','customer_id','amount','tax1_id','tax2_id','note','receipt');
$data->expense_date = $input['expense_date'];
$data->expense_category_id = $input['expense_category_id'];
$data->vendor_id = $input['vendor_id'];
$data->customer_id = $input['customer_id'];
$data->amount = $input['amount'];
$data->tax1_id = $input['tax1_id'];
$data->tax2_id = $input['tax2_id'];
$data->note = $input['note'];
$image = Input::file('receipt');
$filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
Image::make($image->getRealPath())->resize(468, 249)->save('public/uploas/'. $filename);
$data->receipt = $input['image'];
$data->save();
return redirect('expenseinfo');
}
}
表格代码:
<form action="addexpense" enctype="multipart/form-data" >
Receipt:</td><td><input type="file" name="receipt"value="{{Input::old('receipt')}}">
<input style="margin-left:30px"type="submit" value="Add" name="submit">
</form>
答案 0 :(得分:1)
你使用Image::make()
功能做错了。请尝试以下方法:
Image::make($image->getRealPath())->resize(468, 249)->save(public_path() . '/uploads/' . $filename);
答案 1 :(得分:-1)
试试这个:
Image :: make($ image-&gt; getRealPath()) - &gt; resize(468,249) - &gt; save(public_path(&#39; uploads /&#39;)。$ filename); < / p>
有关详细信息,请查看以下链接: https://youtu.be/F92JpVWhDw4