Redirect POST request and keep data. Possible?

后端 未结 4 964
天命终不由人
天命终不由人 2021-01-22 05:11

My problem is simple. I need to upload a file directly to the correct server (which has currently low workload).

Therefore I do:



        
相关标签:
4条回答
  • 2021-01-22 05:18

    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.

    0 讨论(0)
  • 2021-01-22 05:31

    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.

    Or even better: use a serverside loadbalancer and make your HTTP infrastructure transparent to the browser. This is essentially a sysadmin problem.

    0 讨论(0)
  • 2021-01-22 05:34

    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..

    if you want to send your post and your file to a differente location you'll need to use the cUrl library.. but it wont be easy :)

    Good Luck

    0 讨论(0)
  • 2021-01-22 05:36

    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.

    [Edit]

    According to this wikipedia article, the POST data would be converted to GET, which probably won't work for a file upload.

    0 讨论(0)
提交回复
热议问题