drtwqc3744 2013-01-18 04:20
浏览 69

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

I'm trying to transfer a txt file between a client and server using PHP and SOAP.
Can't transfer a txt file to sever floder. But I don't receive any errors.

My code is: 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);

Any help would be much appreciated, thanks!

  • 写回答

1条回答 默认 最新

  • duangelin7513 2013-01-18 04:53
    关注

    Are you looking for all errors? Have you checked the error log file?

    e.g. in your code above I see that you are not checking the return value of curl_exec. What error are you expecting to see, if you are not logging an error explicitly?

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向