views:

269

answers:

1

Hey,

I am new to SOAP and I am trying to learn how to transfer files (.zip files) between a client and server using PHP and SOAP. Currently I have a set up that looks something like this:

enter code here

require('libraries/nusoap/nusoap.php');

$server = new nusoap_server;

$server->configureWSDL('server', 'urn:server');

$server->wsdl->schemaTargetNamespace = 'urn:server';

$server->register('sendFile', array('value' => 'xsd:string'), array('return' => 'xsd:string'), 'urn:server', 'urn:server#sendFile');

But I am unsure on what the return type should be if not a string? I am thinking of using a base64_encode but I am not sure how to. Any advice would be greatly appreciated.

A: 

Transferring files over SOAP is something that gets everybody the first time (myself included). You need to open and read the document and then transfer it as a string. Here's how I would do it.

$handle = fopen("mypackage.zip", "r");
$contents = fread($handle, filesize("mypackage.zip"));
fclose($handle);

//$contents now holds the byte-array of our selected file

Then send $contents as your string through SOAP and reassemble it on the other side.

Jarrod
When you say reassamble, do you mean write it out to a file?
So I tried that will a file and on the server side, the file exist, but when I transfer it back through the client, it is coming up as an empty variable.
Yes, write it out to a new file. If its coming up as an empty after sending the packet then you've probably got a bug in your web service code.
Jarrod
Not sure where this bug is coming from. For example, return filesize("$file"); return "A String"; both work perfectly fine....Do you know of any good tutorials on PHP SOAP?