在PHP中通过SOAP上传一个txt文件

时间:2013-01-18 04:20:25

标签: php soap curl

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

我的代码是: 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 ();

client.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);

非常感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

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

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