附带php的内置SoapClient?

有没有办法可以使用 PHP的内置SoapClient类为请求添加soap附件?它看起来不像是支持,但也许我可以手动构建mime边界?我知道PEAR SOAP库支持它们,但是为了使用它我必须重写我的整个库来使用它.
为什么不用 Data URI scheme发送文件而不是实现 SoapAttachment?这是一个例子:

客户

$client = new SoapClient(null,array(
        'location' => "http://localhost/lab/stackoverflow/a.PHP?h=none",'uri' => "http://localhost/",'trace' => 1
));

// Method 1 Array
// File to upload
$file = "golf3.png";

// First Example
$data = array();
$data['name'] = $file;
$data['data'] = getDataURI($file,"image/png");
echo "Example 1: ";
echo ($return = $client->upload($data)) ? "File Uploaded : $return bytes" : "Error Uploading Files";

// Method 2 Objects
// File to upload
$file = "original.png";

// Second Example
$attachment = new ImageObj($file);
$param = new SoapVar($attachment,SOAP_ENC_OBJECT,"ImageObj");
$param = new SoapParam($param,"param");
echo "Example 2: ";
echo ($return = $client->uploadobj($attachment)) ? "File Uploaded : $return bytes" : "Error Uploading Files";

产量

Example 1: File Uploaded : 976182 bytes
Example 2: File Uploaded : 233821 bytes

服务器

class UploadService {

    public function upload($args) {
        $file = __DIR__ . "/test/" . $args['name'];
        return file_put_contents($file,file_get_contents($args['data']));
    }

    public function uploadobj($args) {
        $file = __DIR__ . "/test/" . $args->name;
        $data = sprintf("data://%s;%s,%s",$args->mime,$args->encoding,$args->data);
        return file_put_contents($file,file_get_contents($data));
    }
}

try {
    $server = new SOAPServer(NULL,array(
            'uri' => 'http://localhost/'
    ));
    $server->setClass('UploadService');
    $server->handle();

} catch (SOAPFault $f) {
    print $f->faultstring;
}

客户端工具

// Function Used
function getDataURI($image,$mime = '') {
    return 'data: ' . (function_exists('mime_content_type') ? 
            mime_content_type($image) : $mime) . ';base64,' . 
            base64_encode(file_get_contents($image));
}


// Simple Image Object
class ImageObj{
    function __construct($file,$mime = "") {
        $this->file = $file;
        $this->name = basename($file);
        if (function_exists('mime_content_type')) {
            $this->mime = mime_content_type($file);
        } elseif (function_exists('finfo_open')) {
            $this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE),$file);
        } else {
            $this->mime = $mime;
        }

        $this->encoding = "base64";
        $this->data = base64_encode(file_get_contents($file));
    }
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...