How can we upload file to root directory of wordpress

Hopefully you have access to your server (i.e. you don’t use a wordpress.com website but have your own server).

You’ll have to connect to the server with either SFTP or SSH (via the use of scp to copy files) or another similar protocol and upload the files to wherever you want. In order to use these, you generally have a special URL and you’ll need a login/password (SFTP) or a security key (SSH). At times, the services offer you a system such as phpMyAdmin. That should also give you access to your server file system and you can upload files through that system.

The PHP code from WordPress will not allow you to just go in and update just any file or directory for obvious security reasons (already the plugins are editable…)

If you do not own the server, depending on your provider, you may be able to ask them to do it for you. There may be extra charges or just plain refusal, again, for security reasons (especially if that provider runs many WordPress websites, it could jeopardize the other sites).