opendir etc all work with the local filesystem.
I don't know that the HTTP protocol allows folders/directories to be uploaded in the same way that files are. If you really don't want to upload the files individually, you may need to zip them into one file, upload that, and then have the script unzip therm and process each file.
Not a trivial job at all.