I want to upload two different files to two different servers located in two different locations.
I have one image file which I want to upload onto my server where the PHP script is hosted and the other video file which I want to upload to some other server not on the same server.
Is there any possibility of doing this? Can anyone explain me how to achieve this if possible?
This is impossible with an HTML form – the
actionattribute only allows for a single URL to be specified.You have a couple of choices here:
Use JavaScript to create two
<iframe>s, fill them with the data you want to submit in a<form>, and then call.submit()on each of the forms. Since you mentioned that the two locations are on different servers, I’ll assume they are on different domains as well – and therefore you will run into trouble with the same-origin policy on at least one of the forms. For that reason, and the fact that quite a few users have JavaScript turned off in their browser, I recommend avoiding this option if possible.Have the PHP script on your server take the
$_POSTdata and send a POST request with that information to the other server. This can easily be done with PHP’s cURL extension, for example. This can be done as follows: