Forward multi-part POST to another page
Okay, I have two sites, we'll call them A and B. Site A has a mutli-part form with a file attachment; Site B has a similar form (which I'm not going to use) and a processing page that it submits to. Due to browser origin policies, I'm adding a "proxy page" to Site B that I can post to from Site A. The proxy page will then need to "forwa开发者_运维百科rd" the data to the processing page and get a response which I will use to generate JSONP for sending back to Site A.
I'd normally use the session or just generate and autosubmit a form on the proxy page but I'm not sure how to do this since it involves a file input tag. I'm thinking I may be able to use something like this: http://www.php.net/manual/en/function.httprequest-send.php
Any ideas?
It'd be relatively trivial with curl.
$post_data = $_POST; // copy over the non-file post data
foreach($_FILES as $key => $filedat) {
$post_data[$key] = '@' . $filedat['tmp_name']; // add the uploaded files to the new field list
}
$ch = curl_init('http://siteb.com/proxy_page')
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$res = curl_exec($ch);
This will undoubtedly need some tweaking/fixing, but should be enough to get you started.
精彩评论