How to I upload to wordpress media library

I have a custom php form that upload images to a folder on my website. Currently that folder is outside the wp-content folder. I want the content of the folder to be automatically uploaded to Google drive. There are plenty of plugins or a zapier solution to do that if the folder is in the wp media folder.

My question is...Can I just upload the images directly to the wp media folder or do I need to use a special wp method/function/api call.