app/Http/Controllers/admin/GoodImagesController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $data = $request->input();
        if($request -> hasFile('images')){
            $profile = $request -> file('images');
            foreach ($profile as $k => $v) {
                $ext = $v->getClientOriginalExtension();
                $temp_name = str_random(10);
                $filename =  $temp_name.'.'.$ext;
                $dirname = date('Ymd',time());
                $v -> move('./uploads/goods/gdphoto/'.$dirname,$filename); 
                $filedir = ('/uploads/goods/gdphoto/'.$dirname.'/'.$filename);
                $goodimages = new GoodImages;
                $goodimages-> gid = $data['gid'];
                $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 store ( Request $ request ) { $ data = $ request -> input ( ) ; if ( $ request -> hasFile ( 'images' ) ) { $ profile = $ request -> file ( 'images' ) ; foreach ( $ profile as $ k => $ v ) { $ ext = $ v -> getClientOriginalExtension ( ) ; $ temp_name = str_random ( 10 ) ; $ filename = $ temp_name . '.' . $ ext ; $ dirname = date ( 'Ymd' , time ( ) ) ; $ v -> move ( './uploads/goods/gdphoto/' . $ dirname , $ filename ) ; $ filedir = ( '/uploads/goods/gdphoto/' . $ dirname . '/' . $ filename ) ; $ goodimages = new GoodImages ; $ goodimages -> gid = $ data [ 'gid' ] ; $ goodimages -> images = $ filedir ; $ res = $ goodimages -> save ( ) ; } if ( $ res ) { return redirect ( '/admin/goodimages' ) -> with ( 'success' , '商品详图添加完成'); } else { return back ( ) -> with ( 'error' , '商品详图添加失败'); } } else { return back ( ) -> with ( 'error' , '图片存储失败'); } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//添加 // dump($data); // 使用request 创建文件上传对象 // dd($profile); // 获取文件后缀名 // 处理文件名称 // 保存文件 // dd($filedir);