php - Laravel upload file in different folder -
public function upload(request $request){ $user = user::findorfail(auth()->user()->id); $filename = time() . '.jpg'; $filepath = public_path('uploads/'); move_uploaded_file($_files['filename']['tmp_name'], $filepath.$filename); move_uploaded_file($_files['filename']['tmp_name'], public_path('uploads/newfolder').$filename); echo $filepath.$filename; }
how can upload same image different folders.
have tried above code , doesn't work in other folder.
you can't run move_uploaded_file
twice same file because name says, moves file, on second run, original file won't exist anymore.
you must copy file:
public function upload(request $request){ $user = user::findorfail(auth()->user()->id); $filename = time() . '.jpg'; $filepath = public_path('uploads/'); move_uploaded_file($_files['filename']['tmp_name'], $filepath.$filename); // note here, copying destination of moved file. // if try origin file, won't work same reason. copy($filepath.$filename, public_path('uploads/newfolder').$filename); echo $filepath.$filename; }
wiki
Comments
Post a Comment