Is it possible to upload files with PHP and SOAP?
Here is the PHP code being used:
$post = "a.txt";
$fp = fopen($post, "r");
$client = new SoapClient("http://api.4shared.com/servlet/services/DesktopApp?wsdl");
$id = $client->createUploadSessionKey("user","pass",-1);
$new_id = $client->uploadStartFile("user","pass",-1, "name", 500*1024);
$dcId = $client->getNewFileDataCenter("user","pass");
$sessKey = $client->createUploadSessionKey("user","pass", -1);
$upload = $client->getUploadFormUrl($dcId, $sessKey);
$res = $client->uploadFinishFile("user","pass", $new_id, $fp);
Yes, it’s possible.
What have you tried so far? Are you using a soap library or did you roll your own? Have you experienced any problems getting file transfer to work? If so what did you try to do and what happened when you tried to do it?
edit – Inspecting the HTTP traffic can be a useful way to debug SOAP servers. Also if the client you are using is flat-out incompatible with a server, you may have to find another client or “roll your own.” I wrote a very simple client which works well with the SOAP servers generated by MS frameworks, it may work well with Java servers too.
If you do end up needing to create your own client, this may help get you started:
SimpleSoapClient.php
Extend this with your own class. See below…
ExampleSoapClient.php
This is actually a production[1] soap client renamed to ‘Example’.
[1] – May not look production quality, but I’m using this and others like it on some cron jobs and PHP sites and it’s working well 🙂