<i id='FEFv3'><tr id='FEFv3'><dt id='FEFv3'><q id='FEFv3'><span id='FEFv3'><b id='FEFv3'><form id='FEFv3'><ins id='FEFv3'></ins><ul id='FEFv3'></ul><sub id='FEFv3'></sub></form><legend id='FEFv3'></legend><bdo id='FEFv3'><pre id='FEFv3'><center id='FEFv3'></center></pre></bdo></b><th id='FEFv3'></th></span></q></dt></tr></i><div id='FEFv3'><tfoot id='FEFv3'></tfoot><dl id='FEFv3'><fieldset id='FEFv3'></fieldset></dl></div>
      <legend id='FEFv3'><style id='FEFv3'><dir id='FEFv3'><q id='FEFv3'></q></dir></style></legend>

    1. <tfoot id='FEFv3'></tfoot>
      • <bdo id='FEFv3'></bdo><ul id='FEFv3'></ul>

      1. <small id='FEFv3'></small><noframes id='FEFv3'>

        PHP SOAP 传输文件

        时间:2023-05-22

        <i id='ccS5P'><tr id='ccS5P'><dt id='ccS5P'><q id='ccS5P'><span id='ccS5P'><b id='ccS5P'><form id='ccS5P'><ins id='ccS5P'></ins><ul id='ccS5P'></ul><sub id='ccS5P'></sub></form><legend id='ccS5P'></legend><bdo id='ccS5P'><pre id='ccS5P'><center id='ccS5P'></center></pre></bdo></b><th id='ccS5P'></th></span></q></dt></tr></i><div id='ccS5P'><tfoot id='ccS5P'></tfoot><dl id='ccS5P'><fieldset id='ccS5P'></fieldset></dl></div>
        <tfoot id='ccS5P'></tfoot>

        • <bdo id='ccS5P'></bdo><ul id='ccS5P'></ul>

          1. <small id='ccS5P'></small><noframes id='ccS5P'>

              <tbody id='ccS5P'></tbody>
            • <legend id='ccS5P'><style id='ccS5P'><dir id='ccS5P'><q id='ccS5P'></q></dir></style></legend>
                • 本文介绍了PHP SOAP 传输文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试学习如何使用 PHP 和 SOAP 在客户端和服务器之间传输文件(.zip 文件).目前我有一个看起来像这样的设置:

                  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:

                  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');
                  

                  但是如果不是字符串,我不确定返回类型应该是什么?我正在考虑使用 base64_encode.

                  But I am unsure on what the return type should be if not a string? I am thinking of using a base64_encode.

                  推荐答案

                  为了更清楚,我已经发布了 server.php 代码和 client.php 代码.请看下图:

                  To be more clear I have posted both the server.php code and client.php code. Please see below:

                  require_once('lib/nusoap.php'); //include required class for build nnusoap web service server
                  
                    // Create server object
                     $server = new soap_server();
                  
                     // configure  WSDL
                     $server->configureWSDL('Upload File', 'urn:uploadwsdl');
                  
                     // Register the method to expose
                      $server->register('upload_file',                                 // method
                          array('file' => 'xsd:string','location' => 'xsd:string'),    // input parameters
                          array('return' => 'xsd:string'),                             // output parameters
                          'urn:uploadwsdl',                                            // namespace
                          'urn:uploadwsdl#upload_file',                                // soapaction
                          'rpc',                                                       // style
                          'encoded',                                                   // use
                          'Uploads files to the server'                                // documentation
                      );
                  
                      // Define the method as a PHP function
                  
                      function upload_file($encoded,$name) {
                          $location = "uploads\".$name;                               // Mention where to upload the file
                          $current = file_get_contents($location);                     // Get the file content. This will create an empty file if the file does not exist     
                          $current = base64_decode($encoded);                          // Now decode the content which was sent by the client     
                          file_put_contents($location, $current);                      // Write the decoded content in the file mentioned at particular location      
                          if($name!="")
                          {
                              return "File Uploaded successfully...";                      // Output success message                              
                          }
                          else        
                          {
                              return "Please upload a file...";
                          }
                      }
                  
                      // Use the request to (try to) invoke the service
                      $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
                      $server->service($HTTP_RAW_POST_DATA); 
                  

                  ====================================================================

                  =====================================================================

                  require_once('lib/nusoap.php'); //include required class for build nnusoap web service server
                     $wsdl="http://localhost:81/subhan/webservice3/server.php?wsdl";  // SOAP Server
                  
                     if($_POST['submit'])
                     {
                         $tmpfile = $_FILES["uploadfiles"]["tmp_name"];   // temp filename
                         $filename = $_FILES["uploadfiles"]["name"];      // Original filename
                  
                         $handle = fopen($tmpfile, "r");                  // Open the temp file
                         $contents = fread($handle, filesize($tmpfile));  // Read the temp file
                         fclose($handle);                                 // Close the temp file
                  
                         $decodeContent   = base64_encode($contents);     // Decode the file content, so that we code send a binary string to SOAP
                      }   
                  
                     $client=new soapclient($wsdl) or die("Error");   // Connect the SOAP server
                     $response = $client->__call('upload_file',array($decodeContent,$filename)) or die("Error");  //Send two inputs strings. {1} DECODED CONTENT {2} FILENAME
                  
                     // Check if there is anny fault with Client connecting to Server
                     if($client->fault){
                          echo "Fault {$client->faultcode} <br/>";
                          echo "String {$client->faultstring} <br/>";
                     }
                     else{
                          print_r($response); // If success then print response coming from SOAP Server
                     }
                  
                  
                  <form name="name1" method="post" action="" enctype="multipart/form-data">
                  <input type="file" name="uploadfiles"><br />
                  <input type="submit" name="submit" value="uploadSubmit"><br />
                  </form>
                  

                  ================================================

                  =================================================

                  您需要做的就是下载 nusoap.php,它将在soap 库中看到 http://sourceforge.net/projects/nusoap/

                  All you need to do is download the nusoap.php which will be seen in soap library http://sourceforge.net/projects/nusoap/

                  这是经过全面测试的,它将 100% 正常工作.

                  This is fully tested and it will 100% work without fail.

                  这篇关于PHP SOAP 传输文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:是否可以在 PHP 中咖喱方法调用? 下一篇:SoapClient:如何传递多个同名元素?

                  相关文章

                  最新文章

                    <legend id='BykBk'><style id='BykBk'><dir id='BykBk'><q id='BykBk'></q></dir></style></legend>

                    1. <i id='BykBk'><tr id='BykBk'><dt id='BykBk'><q id='BykBk'><span id='BykBk'><b id='BykBk'><form id='BykBk'><ins id='BykBk'></ins><ul id='BykBk'></ul><sub id='BykBk'></sub></form><legend id='BykBk'></legend><bdo id='BykBk'><pre id='BykBk'><center id='BykBk'></center></pre></bdo></b><th id='BykBk'></th></span></q></dt></tr></i><div id='BykBk'><tfoot id='BykBk'></tfoot><dl id='BykBk'><fieldset id='BykBk'></fieldset></dl></div>
                    2. <small id='BykBk'></small><noframes id='BykBk'>

                    3. <tfoot id='BykBk'></tfoot>
                      • <bdo id='BykBk'></bdo><ul id='BykBk'></ul>