3

I am having a problem transferring files using NuSOAP. I understand that you can read a file and transfer it as a string, but it's not working. Here is an example:

Client:

require('libraries/nusoap/nusoap.php');
$url = "http://www.example.com";

$client = new nusoap_client($url);
args = array('file_name' => 'myfile.zip');
$return = $client->call('getFile', array($args));

if(empty($return){
    echo "WHY IN THE WORLD IS THIS EMPTY!!!!!";
}

Server:

require('libraries/nusoap/nusoap.php');
$server = new nusoap_server;

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

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

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

function getFile($value){

$returnData= "";
$filePath=$value['file_path'];
$mode="r";

  if (floatval(phpversion()) >= 4.3) {
         $returnData= file_get_contents($filePath);
     } else {
         if (!file_exists($filePath)){ 
          return -3;
         }

         $handler = fopen($filePath, $mode);
         if (!$handler){ 
          return -2;
         }

         $returnData= "";
         while(!feof($handler)){
             $returnData.= fread($handler, filesize($filePath));
         }//end  while

         fclose($handler);
     }//end else

return $returnData;
}

Here is the really strange part. If I return the file name or file size or something like that, it will work. It will just not return the file itself. Help please.

SteB
  • 1,999
  • 4
  • 32
  • 57
user293313
  • 227
  • 1
  • 2
  • 10
  • I edited the question to include a missing $ from before value and a ; from the end of the line: $filePath=value['file_path'] – SteB Nov 30 '12 at 12:44

1 Answers1

0

In the server side getFile function you should return base64_encode($returnData);

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Cizu
  • 1
  • 1