How does php call WebService to upload files? because our company wants to perform secondary development on OA, OA is developed using java! Now there is an interface for uploading files. The example is for c #, and I don't know C #. PHP is also a beginner who hasn't used the interface to upload files. I don't know how to do it!
The following is a description of the document. I can see if there are any great gods or moderators help me to convert it into a PHP language for me to observe and learn.
UploadService file upload service.
Request path:/seeyon/uploadService. do? Method = processUploadService
Parameters:
Token string obtained after login verification. I can get
SenderLoginName string initiator login name I can get
Return value: string
The generated attachment id is returned. if multiple files are uploaded, the IDS are separated by the "|" symbol.
C # example:
URL preUrl = null; URLConnection uc = null; preUrl = new URL (" http://XXX.XXX.XXX.XXX/seeyon/uploadService.do ? Method = processUploadService "+" & senderLoginName = "+" zy "+" & token = "+" 997a7cdc-2399-47e8-991e-96c859cccc7f "); String s = parameters. toString (); uc = preUrl. openConnection (); HttpURLConnection hc = (HttpURLConnection) uc; hc. setDoOutput (true); hc. setUseCaches (false); hc. setRequestProperty ("contentType", "charset = utf-8"); hc. setRequestMethod ("POST"); BufferedInputStream input = new BufferedInputStream (New FileInputStream ("c:/ldap 文 .doc"); String BOUNDARY = "--------------------------- 7d4a6d158c9 7d4a6d158c9"; // delimiter String fileName = "ldap 文 .doc"; StringBuffer sb = new StringBuffer (); sb. append ("--"); sb. append (BOUNDARY); sb. append ("\ r \ n"); sb. append ("Content-Disposition: form-data; \ r \ n name = \" 1 \"; filename = \ "" + fileName + "\" \ r \ n "); sb. append ("Content-Type: application/msword \ r \ n"); hc. setRequest Property ("Content-Type", "multipart/form-data; boundary =" + "--------------------------- 7d4a6d158c9 "); byte [] end_data = ("\ r \ n --" + BOUNDARY + "-- \ r \ n "). getBytes (); DataOutputStream dos = new DataOutputStream (hc. getOutputStream (); dos. write (sb. toString (). getBytes ("UTF-8"); int cc = 0; while (cc = input. read ())! =-1) {dos. write (cc);} dos. write (end_data); dos. flush (); dos. close (); FileOutputStream file = new FileOutputStream ("c:/test.txt"); InputStream is = hc. getInputStream (); int ch; while (ch = is. read ())! =-1) {file. write (ch);} if (is! = Null) is. close ();
Reply to discussion (solution)
Search for sock file Upload
Search for sock file Upload
Some people say that curl is different from this?
For 100, please kindly give the code and do not copy the online
The younger brother has been in contact with PHP for less than four months.
From the perspective of your C # code, it is basically the same as the php sock file upload code.
The specific implementation needs to be elaborated.
If the service provider complies with the standard http protocol, it is easier to use curl.
Debugging cannot be performed because it cannot receive feedback from the service provider.
Function uploadFileToOA ($ file = array (), $ senderLoginName)
{
$ Client = new \ SoapClient ("http://XXX.XXX.XXX.XXX/xxx? Wsdl ");
$ Param = array ("userName" => "userName", "password" => "password ");
$ Token = $ client->__ soapCall ('authenticate', array ($ param ));
$ PostUrl = "http://XXX.XXX.XXX.XXX/XXXLoginName." & token = ". $ token-> return-> id;
$ Fields = array ("file" => $ file );
$ Curl = curl_init ($ PostUrl );
Curl_setopt ($ curl, CURLOPT_POST, true );
Curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ fields );
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 );
$ Result = curl_exec ($ curl );
Curl_close ($ curl );
Return $ result;
}
A tear, too difficult, and finally got it done