不保存数据库中的图像路径

时间:2017-10-04 19:04:48

标签: php laravel

我想上传照片和文字

但照片路径未保存在表格内,但照片已上传到目录

控制器代码

namespace App\Http\Controllers;
use App\Http\Requests\singlereq;
use App\infouser;
class singleupload extends Controller
{
    public function uploadform()
    {
        return view('singleupload.upload_form');
    }
    public function uploadSubmit(singlereq $request)
    {
        $file = $request->file('imgs');
        $file->move('img', $file->getClientOriginalName()); 
        $product = infouser::create($request->all());
        return 'OK Upload successful!';
    }
}

1 个答案:

答案 0 :(得分:1)

在代码下方使用。获取图像名称并设置表格列(your_file)您的表格中是列名称。

$file = $request->file('imgs');
$file->move('img', $file->getClientOriginalName()); 
$input = $request->all();
$name = $file->getClientOriginalName();
$input['your_file'] = $name; 
$product = infouser::create($input);
return 'OK Upload successful!';