[英]PHP Fatal error: Call to undefined method soapclient::_call()
I am working on a SOAP service to upload pictures and I get this error when I upload a picture with the webservice.我正在使用 SOAP 服务上传图片,当我使用网络服务上传图片时出现此错误。 I dont have too much experience with php and SOAP webservices so I will apreciate any help.
我对 php 和 SOAP 网络服务没有太多经验,所以我会感谢任何帮助。 I am using a php library call it nusoap .
我正在使用一个名为 nusoap的 php 库。 This is my code:
这是我的代码:
require_once('lib/nusoap.php'); //include required class for build nnusoap web service server
// Create server object
$server = new soap_server();
// configure WSDL
$server->configureWSDL('Upload File', 'urn:uploadwsdl');
// Register the method to expose
$server->register('upload_file', // method
array('file' => 'xsd:string','location' => 'xsd:string'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:uploadwsdl', // namespace
'urn:uploadwsdl#upload_file', // soapaction
'rpc', // style
'encoded', // use
'Uploads files to the server' // documentation
);
// Define the method as a PHP function
function upload_file($encoded,$name) {
$location = "uploads\\".$name; // Mention where to upload the file
$current = file_get_contents($location); // Get the file content. This will create an empty file if the file does not exist
$current = base64_decode($encoded); // Now decode the content which was sent by the client
file_put_contents($location, $current); // Write the decoded content in the file mentioned at particular location
if($name!="")
{
return "File Uploaded successfully..."; // Output success message
}
else
{
return "Please upload a file...";
}
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
require_once('lib/nusoap.php'); //include required class for build nnusoap web service server
$wsdl="http://{servidor}/WebServiceSOAP/server.php?wsdl"; // SOAP Server
if($_POST["submit"])
{
$tmpfile = $_FILES["uploadfiles"]["tmp_name"]; // temp filename
$filename = $_FILES["uploadfiles"]["name"]; // Original filename
$handle = fopen($tmpfile, "r"); // Open the temp file
$contents = fread($handle, filesize($tmpfile)); // Read the temp file
fclose($handle); // Close the temp file
$client=new soapclient($wsdl) or die("Error"); // Connect the SOAP server
$response = $client->_call('upload_file',array($filename)) or die("Error"); //Send two inputs strings. {1} DECODED CONTENT {2} FILENAME
}
//$client=new soapclient($wsdl) or die("Error"); // Connect the SOAP server
//$response = $client->__call('upload_file',array($decodeContent,$filename)) or die("Error"); //Send two inputs strings. {1} DECODED CONTENT {2} FILENAME
// Check if there is anny fault with Client connecting to Server
if($client->fault){
echo "Fault {$client->faultcode} <br/>";
echo "String {$client->faultstring} <br/>";
}
else{
print_r($response); // If success then print response coming from SOAP Server
}
<form name="name1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="uploadfiles"><br />
<input type="submit" name="submit" value="uploadSubmit"><br />
</form>
I get this error when I press the upload button.当我按下上传按钮时出现此错误。 This is my error_log:
这是我的错误日志:
[14-Apr-2018 22:44:57 America/Chicago] PHP Notice: Undefined index: submit in /home/XXXX/public_html/WebServiceSOAP/client.php on line 5
[14-Apr-2018 22:44:57 America/Chicago] PHP Notice: Undefined variable: client in /home/XXXX/public_html/WebServiceSOAP/client.php on line 22
[14-Apr-2018 22:44:57 America/Chicago] PHP Notice: Trying to get property of non-object in /home/XXXX/public_html/WebServiceSOAP/client.php on line 22
[14-Apr-2018 22:44:57 America/Chicago] PHP Notice: Undefined variable: response in /home/XXXX/public_html/WebServiceSOAP/client.php on line 27
[14-Apr-2018 22:45:05 America/Chicago] PHP Fatal error: Call to undefined method soapclient::_call() in /home/XXXX/public_html/WebServiceSOAP/client.php on line 15
There Are few Problems In Your Code你的代码几乎没有问题
isset
function for checking the submission.isset
函数来检查提交。Just enable soap extension then the problem will be solved.只需启用soap扩展即可解决问题。
Open php.ini and change ;extension=soap to extension=soap .打开 php.ini 并将;extension=soap更改为extension=soap 。 Save changes and restart the Apache server.
保存更改并重新启动 Apache 服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.