I have to send a picture to a webservice. The web service should receive the image as bytes (mayby bytearray) - not as a string... How do I convert the images to "byte" or bytearray?
I have tried this (without succes):
$image1 = file_get_contents("LINK TO IMAGE");
$image1BinaryData = "".base64_encode($image1)."";
Any help will be appreciated...
Have you tried to directly read the image as binary data?
<?php
$filename = "image.png";
$file = fopen($filename, "rb");
$contents = fread($file, filesize($filename));
fclose($file);
?>
This is the actual byte array equivalent to what is generated in C# and Java.
$data = file_get_contents("test.jpg");
$array = array();
foreach(str_split($data) as $char){
array_push($array, ord($char));
}
var_dump(implode(' ', $array));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With