如何处理图像上传的更新

时间:2017-12-24 06:07:00

标签: laravel file-upload controller crud

最近我正在尝试使用laravel 5.5并创建简单的上传和更新图像

这是我的商店控制器

$input = $request->all();


        $this->validate($request, [ 
            'photo' => 'sometimes|image|mimes:jpeg,png,jpg,gif,svg|max:500',
        ]);



        if ($request->hasFile('photo')) {
            $photo = $request->file('photo');
            $ext = $photo->getClientOriginalExtension();

            if ($request->file('photo')->isValid()) {
                $photo_name = date('YmdHis'). ".$ext";
                $photoName = time().'.'.$request->photo->getClientOriginalExtension();
                $request->photo->move(public_path('photo-upload'), $photoName);
                $upload_path = public_path('photo-upload');
                $input['photo'] = $photoName;
            }
        }

控制器更新

if ($request->hasFile('photo')) {
            // delete the old/previous one
            $exist = Storage::disk('photo')->exists($student->photo);
            if (isset($student->photo) && $exist) {
                $delete = Storage::disk('photo')->delete($siswa->photo);
            }

            // upload new one
            $photo = $request->file('photo');
            $ext = $photo->getClientOriginalExtension();
            $photoName = time().'.'.$request->foto->getClientOriginalExtension();
            if ($request->file('photo')->isValid()) {
                $upload_path = 'photo-upload';
                $request->file('photo')->move($upload_path, $phptpName);
                $input['photo'] = $iphotoName;
            }
        }

存储方法工作正常,它将图像上传到右侧文件夹然后更新数据库

问题在于更新,它更新了数据库,但没有将图像上传到照片上传文件夹

有什么建议吗?

由于

0 个答案:

没有答案