我正在尝试使用 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);
任何帮助将不胜感激,谢谢!