Upload file to remote server (PHP)
I have a scenario where I have a page on one server which prompts a user to upload a file. I need this file to be uploaded to a different server with a larger storage facility. I then need to get the absolute p开发者_运维问答ath of where the file now resides on the server sent back to the originating page.
The file size that will be around 15mb, so they aren't small files, and I'd like to avoid double uploading if possible (uploading to the server, then pushing over to remote server).
Any direction on this is appreciated.
If the remote server is also running as a web server you could create the upload form and have the submit action go to the other server. The disadvantage of this is that some browsers will treat this as a potential security hole and warn the user when the page is displayed, but you can get around this by creating a reverse proxy entry in your main web server that points to the file server.
You could upload the file directly to the storage server, specifying a unique key in the hidden form like:
<form action="http://mystorage.com/upload" method="post">
<input type="file" name="myfile" />
<input type="hidden" name="key" value="asdf1234sadfasfd34565xx" />
</form>
Then simply send a RESTful request from the storage server to your primary server, stating the unique key and the absolute path... or fetch the absolute path by "asking" your storage server when the primary server needs to know the file location... limitless possibilities ahead!
If the second server can be accessible from the web then just make the html form post to the storage server then redirect to the first web server. During the redirect you could pass back additional variables via the GET query string.
精彩评论