0

我正在尝试使用 PHP 和 SOAP 在客户端和服务器之间传输 txt 文件。
无法将 txt 文件传输到服务器。但我没有收到任何错误。

我的代码是:Service.php

class Service 
{
    public function addFile($params) 
    {
        $uploads_dir = '/uploads';

        foreach ( $_FILES ["txt"] ["error"] as $key => $error ) {

            print_r($error);

            if ($error == UPLOAD_ERR_OK) {
                $tmp_name = $_FILES ["txt"] ["tmp_name"] [$key];
                $name = $_FILES ["txt"] ["name"] [$key];
                move_uploaded_file ( $tmp_name, "$uploads_dir/$name" );
            }
        }
    }
}

$server = new SoapServer ( 'Service.wsdl', array ('soap_version' => SOAP_1_2 ) );
$server->setClass ( 'Service' );
$server->handle ();

客户端.php

ini_set('soap.wsdl_cache_enabled', "0");

$soap = new SoapClient('http://xxx.xxx.xxx.xxx/Service.php');

$fullfilepath = 'D:\test.txt';
$B64File = base64_encode($fullfilepath);
$upload_url = 'http://xxx.xxx.xxx.xxx/Service.php';
$title = '';
$params = array(
        'photo'=>array('array' => $B64File),
        'title'=>$title
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$response = curl_exec($ch);
curl_close($ch);
$soap->addFile($params);

任何帮助将不胜感激,谢谢!

4

1 回答 1

0

你在寻找所有的错误吗?你检查过错误日志文件吗?

例如,在您上面的代码中,我看到您没有检查 curl_exec 的返回值。如果您没有明确记录错误,您希望看到什么错误?

于 2013-01-18T04:53:41.947 回答