I have a base64 text, which is huge, posted from Ajax. In console, I can see the code, and if i copy and paste it into a base64 image converter it works fine.
In PHP $_POST
is always empty, but php://input
shows all the information, which is a JSON with four parts within the array. Under the 'imgData' part, the image binary code is complete and works, but if I do this:
$data = json_decode(file_get_contents('php://input'));
(A) print_r($data); // Shows all the image data under [imgData]
(B) print_r($data->imgData); // Only shows a small part of the image data
Here is an example of the output (A):
stdClass Object ( [switch] => addImage [table] => tbl_images [propid] => [imgData] => data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAYAAACI7Fo9AAAAHGlET1QAAAACAAAAAAAAAH0AAAAoAAAA
Here is the exmaple output (B):
data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAYAAACI7Fo9AAAAHGlET1QAAAACAA
But (B) is only part of the data? Any reason for this ?
UPDATE
$data = json_decode(file_get_contents('php://input'));
(A) var_dump($data);
(B) var_dump($data->imgData);
The above are now equal and give the same string sizes.
When I put this into a SQL query:
$detail = "Property_Id, Image_Data ) VALUES ( 213, " . $data->imgData;
$sql = "INSERT INTO " . $table . " ( " . $detail . " )";
echo $sql;
$addQ = $mysqli->query($sql);
echo 'image added';
print_r($mysqli->error);
} else {
echo "No params added";
}
It still does not show the end of the $sql string ?