PHP: How to forward on $_FILES using cURL
I'm trying to use cURL to forward on a http request from a form in a web application I'm developing. Essentially I need to submit the same form 开发者_开发百科twice on different servers, for the second server I'm adding some security measures to the post data.
I can receive $_POST information on the second form perfectly fine, however I'm having major troubles with my $_FILES - I've tried separating the two so there's a separate request for post and files data but still no luck.
Is this possible?
<?php
$filename = '/foo/bar';
$postargs = array(
'foo' =>'bar', //normal postfield
'fileentry' => '@'.$filename //be sure to give it as an absolute path!, $_FILES['fileentry']['tmp_name'] usually has this
);
$ch = curl_init();
//other stuff with curl
curl_setopt($ch,CURL_POSTFIELDS, $postargs);//give as array for proper encoding.
curl_exec();
?>
You can:
- force PHP not to process the files (see this question for details);
- use curl to submit
file_get_contents('php://input')
as raw post data (see this question for details). You will also have to forward some HTTP headers withCURLOPT_HTTPHEADER
, namelyContent-Length
andContent-type
.
This avoids hitting the filesystem.
精彩评论