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
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');
Please make sure these things. if you are going to update file on different location.
Now change verify the changes in code as follow.
$fileName = time() . '.' .$request->file('User_jpeg')->getClientOriginalExtension();
$storageLocation = '../../WEBSITE-FILE/TEAM/USER'; //it should be absolute path of storage location.
$request->file('User_jpeg')
->storeAs($storageLocation, $fileName);
$request->file('User_jpeg')
->storeAs($storageLocation . '/User_Profile_Image', $fileName);
Edits:
As per the requested current status, try this.
public function store(Request $request) {
$this->validate($request, [ 'image' => 'required|image|mimes:jpeg,png,jpg|max:2048', ]); $input['image'] = time().'.'.$request->image->getClientOriginalExtension();
$request->image->move(public_path('folder-a'), $input['image']);
$fileSrc = public_path('folder-a') . $input['image'];
$fileDest = public_path('folder-b') . $input['image'];
\File::copy($fileSrc, $fileDest);
Service::create($input);
return back()->with('success',' CREATED SUCCESSFULLY .');
}