如何在php中将图像转换为字节数组格式


how to convert an image into byte array format in php

我专注于构建一个新的项目,将搜索图像并显示结果。为此,我使用使用SOAP客户端的.NET web服务。

但是在调用UploadFile()函数时,第一个参数是图像的字节数组格式,但是每次它都显示为null..

我的代码如下…

  $client = new SoapClient("http://www.myserviceurl.com?wsdl");
  $byte_array = file_get_contents('mypic.jpg');
  $image = base64_encode($byte_array);
  $result=$client->Upload($image, "mypic.jpg");
  print_r($result);

$result打印是这样的…

stdClass Object ( [UploadFileResult] => Buffer cannot be null. Parameter name: buffer )

请帮助我说一下如何获得图像上传的bytearray ..提前感谢……

检查

<?php
$filename = "mypic.jpg";//Image path
$file = fopen($filename, "rb");
$contents = fread($file, filesize($filename));
fclose($file);
?>

编码快乐! !