Sending a File to a server with NuSoap

  • Hi,
    I've maked a client that send some strings to a soap server and it works fine. Now I've to send a file too. This is the related wsdl part:

    <wsdl:part name="email" type="xsd:string"/>
    <wsdl:part name="p0" type="xsd:string"/>
    <wsdl:part name="dh" type="apachesoap:DataHandler"/>

    My client is client.php:

    require 'assets/lib/nusoap.php';
    $email = $_POST['email'];
    $tmpZip = 'tmp/';
    $p0 = $_POST['p0'];
    //instantiate the NuSOAP class and define the web service URL:
    $client = new nusoap_client('');
    $client->soap_defencoding = 'UTF-8';
    $client->decode_utf8 = false;
    //check if there were any instantiation errors, and if so stop execution with an error message:
    $error = $client->getError();
    if ($error) {
        die("client construction error: {$error} \n");
    $user = 'frank';
    $psw = 'frank2013';
    //authenticate to the service:
    $client->setCredentials($user, $psw);
    //file part
    $tmpfile = BASE_PATH.'/'.$tmpZip;
    $handle = fopen($tmpfile, "r");                  // Open the temp file
    $contents = fread($handle, filesize($tmpfile));  // Read the temp file
    //perform a function call with parameters:
    $param = array(
        'email' => $email,
        'p0' => $p0,
        'dh' => $contents
    $answer = $client->call('newContact', $param, '', '', '', true, 'rpc', '');
    //check if there were any call errors, and if so stop execution with some error messages:
    if ($client->fault) {
        echo '<h2>Fault</h2><pre>';
        echo '</pre>';
    } else {
        $err = $client->getError();
        if ($err) {
            echo  $err ;
        } else {
            //echo substr($answer, 46, 2);
            echo $answer;

    If I remove the file part, it send correctly the two strings. How can I send the file?
    Thank you very much