开发者

PHP to consume webservice that needs xs:base64Binary

I've got a webservice which expects a parameter of typ开发者_高级运维e "xs:base64Binary" - this is a file to store in the database.

I'm trying to consume the service using PHP 5's native webservice classes. I've tried a few things:

// Get the posted file
$file = file_get_contents($_FILES['Filedata']['tmp_name']);

// Add the file, encoding it as a base64
$parameters = array("fileBytes" => base64_encode($file));

// Call the webservice
$response = $client->attachFile($parameters); 

The result is an error saying "Bad Request." If the file is a text file and I don't base64_encode, it works fine. Problem results when posting a binary file such as an image.

Anyone know the trick here?

EDIT 1

Also problematic is if I encode the text file, it seems to work but of course it's encoded and ends up being junk once downloaded and viewed again (i.e, the text is encoded and doesn't seem to get de-coded by the server).


As far as I know, base64_encode() should be doing the job. Are you 100% sure $file contains something? Have you made a dump?


Ok, so it seems there is no need to use base64_encode. The file_get_contents already puts it into the required format.

Additionally, the problem was because I had the server side config setting for the maxArrayLength too low.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜