I need to POST some data to a PHP page using cURL, and the request contains three p开发者_Go百科arameters:
- Two of them are regular text values
- One is a Base64 encoded file
I've noticed that the Base64 value is corrupted during the transmission.
This is the code that's sending the request:
$filename = "img2.jpg"; //A sample image file
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
$base64 = base64_encode($data);
$postData = "id=1234&sometext=asdasd&data=" . $base64;
$ch = curl_init("http://mydomain/post.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$httpResponse = curl_exec($ch);
curl_close($ch);
Any tips?
Maybe you should use urlencode() because the +
and =
in a base64 string?
Make sure that the size of the post data does not exceed your 'max_post_size' in your php.ini file.
A fair guess is that the encoding adds + - signs, which mess up your data.
After encode, try to add replace + to - (And backwards on recieve of course.)
Ref: http://en.wikipedia.org/wiki/Base64#URL_applications
精彩评论