My problem is simple. I need to upload a file directly to the correct server (which has currently low workload).
我的问题很简单。我需要将文件直接上传到正确的服务器(目前工作负载较低)。
Therefore I do:
所以我这样做:
then i print my form like
然后我打印我的表格像
"...
Now I would like to shift this step to when the upload starts, like so:
现在我想将此步骤转移到上传开始时,如下所示:
this url should do a redirect to the "real" server.
这个网址应该重定向到“真正的”服务器。
So that the upload page doesn't slow down loading and I have static html code that I can cache, embed etc...
所以上传页面不会减慢加载速度,我有静态HTML代码,我可以缓存,嵌入等...
Problem is that this works perfetly fine with get requests but not with post requests.
问题是,这对于get请求很好,但不适用于post请求。
The request seems like to get transformed into a get request when redirecting using the location header. All post data is lost.
当使用location头重定向时,请求似乎转换为get请求。所有帖子数据都会丢失。
Is this impossible or am I doing it wrong? And yes, I considered a remote dynamic Javascript that prints the html code with the correct server in the first place. I would rather like not to do that...
If you really want to load balance through the code while potentially caching the page with the upload form, first select the default download server (url); then, onSubmit call the server and find the best upload target and adjust the action attribute accordingly.
With this method, users who do not activate JS still get what they want, users with JS enabled get the better upload target, and you can still cache. Additionally, the timing of the cache request could potentially be more opportunistic, since the URL request will occur very shortly before the actual upload.
The only hitch will be the call to get the URL, which you can more easily performance tune (I imagine) than the process you are describing above. Uploading a file twice through a header directive and/or cURL call don't seem like a good tradeoff for caching a single html file, IMO. But I don't know what you're up against, either.
If you don't want to heavily administer the server environment and introduce load balancing, this is the option I would suggest.
如果您不想大量管理服务器环境并引入负载平衡,这是我建议的选项。
Note, also, I am not a server administrator by trade.
另请注意,我不是贸易服务器管理员。
#2
2
You could try returning a code 302 (temporary moved), not 100% that would let your browser post the data to the changed url though, but it's worth something to check out.
According to this wikipedia article, the POST data would be converted to GET, which probably won't work for a file upload.
根据这篇维基百科文章,POST数据将转换为GET,这可能不适用于文件上传。
#3
1
This is not a good solution. The file will be uploaded in it's entirety before the PHP script is even started. This means that if you succeed with what you're trying to do the client will have to upload the file twice!
I recommend that you try to figure out which server to send the request to when you're creating the form, so the action attribute in the form tag will point directly to the lesser loaded machine.
i might be wrong but.. your form's action points to ?action=target and in your rest.php you do a header to "?action=test" well of course you wont find your $POST nor your $FILES!... a header() does not send those variables..