Upload image to two different folder locations using Laravel 5.8

前端 未结 2 560
野性不改
野性不改 2021-01-28 05:44

This Code save image in only one folder. I want to upload the image at the same time in two different folders, example folder-one and folder-two

my controler

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 06:04

    In controller:

    public function store(Request $request){
    
            if($request->User_jpeg != ''){ //check file has selected 
    
                $file = $request->User_jpeg;
    
                $path = base_path('public/folder-one/');
    
                $filename = time() . '_' . $file->getClientOriginalName();
    
                $file->move($path, $filename); 
    
                \File::copy($path.$filename,base_path('public/folder-two/'.$filename));
            }
    
            user::create([
                'photo_jpeg' => $filename,
            ]);
    
        }
    

    In route file (web.php):

    Route::post('save-image', 'YourController@store');
    

提交回复
热议问题