app/Http/Controllers/admin/GoodImagesController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        if($request -> hasFile('images')){
            $profile = $request -> file('images');
            $ext = $profile->getClientOriginalExtension();
            $temp_name = str_random(10);
            $filename =  $temp_name.'.'.$ext;
            $dirname = date('Ymd',time());
            $profile -> move('./uploads/goods/gphoto/'.$dirname,$filename); 
            $filedir = ('/uploads/goods/gphoto/'.$dirname.'/'.$filename);
            $goodimages = GoodImages::find($id);
            $goodimages-> images = $filedir;
            $res = $goodimages->save();
            if($res){
                return redirect('/admin/goodimages')->with('success','商品详图添加完成');
            }else{
                 return back()->with('error','商品详图添加失败');
            }
        } else {
            return back() -> with('error','图片存储失败');
        }
    }
public function update ( Request $ request , $ id ) { if ( $ request -> hasFile ( 'images' ) ) { $ profile = $ request -> file ( 'images' ) ; $ ext = $ profile -> getClientOriginalExtension ( ) ; $ temp_name = str_random ( 10 ) ; $ filename = $ temp_name . '.' . $ ext ; $ dirname = date ( 'Ymd' , time ( ) ) ; $ profile -> move ( './uploads/goods/gphoto/' . $ dirname , $ filename ) ; $ filedir = ( '/uploads/goods/gphoto/' . $ dirname . '/' . $ filename ) ; $ goodimages = GoodImages :: find ( $ id ) ; $ goodimages -> images = $ filedir ; $ res = $ goodimages -> save ( ) ; if ( $ res ) { return redirect ( '/admin/goodimages' ) -> with ( 'success' , '商品详图添加完成'); } else { return back ( ) -> with ( 'error' , '商品详图添加失败'); } } else { return back ( ) -> with ( 'error' , '图片存储失败'); } }
Update the specified resource in storage.
Update the specified resource in storage .
// 使用request 创建文件上传对象 // dd($profile); // 获取文件后缀名 // 处理文件名称 // 保存文件 // dd($filedir); // dd($goodimages);