POST Base64 encoded data in PHP
16,327
Solution 1
Maybe you should use urlencode() because the +
and =
in a base64 string?
Solution 2
Make sure that the size of the post data does not exceed your 'max_post_size' in your php.ini file.
Author by
Mark
Updated on July 09, 2022Comments
-
Mark almost 2 years
I need to POST some data to a PHP page using cURL, and the request contains three parameters:
- 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?