简体   繁体   English

将文件上传到远程服务器(PHP)

[英]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 path 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). 文件大小约为15mb,因此它们不是小文件,如果可能的话,我希望避免重复上传(上传到服务器,然后再推送到远程服务器)。

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. 如果远程服务器也作为Web服务器运行,则可以创建上载表单,并使Submit操作转到另一台服务器。 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. 这样做的缺点是,某些浏览器会将其视为潜在的安全漏洞,并在显示页面时警告用户,但是您可以通过在主Web服务器中创建指向文件服务器的反向代理条目来解决此问题。

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! 然后,只需从存储服务器向主服务器发送RESTful请求,说明唯一密钥和绝对路径...,或者在主服务器需要知道文件位置时通过“询问”存储服务器来获取绝对路径。 。无限的可能!

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. 如果可以从Web访问第二台服务器,则只需将html表单发布到存储服务器,然后重定向到第一台Web服务器。 During the redirect you could pass back additional variables via the GET query string. 在重定向期间,您可以通过GET查询字符串传回其他变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM