Hi, I'm experimenting with the api, I'm interested in create a bot to upload images. This is my code (I'm using the Snoopy.php class):
# get token
$getToken = array(
'action' => 'query',
'prop' => 'info',
'intoken' => 'edit',
'titles' => 'Wiki1',
'format' => 'php');
echo "<br/>";
if(!$snoopy->submit($api_url, $getToken))
echo "TOKEN DENIED";
else
echo "GOT TOKEN";
echo "<br/>";
$array_ = unserialize($snoopy->results);
$myFile = fopen("/var/www/dib.jpg","r");
$returned = fread($myFile, 500);
while($devuelto != false) {
$fileContent .= $returned;
$returned = fread($myFile, 500);
}
#upload
$uploadVars['format'] = 'php';
$uploadVars['action'] = 'upload';
$uploadVars['filename'] = 'wikip.png';
$uploadVars['url'] = 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png';
$uploadVars['file'] = $fileContent;
$uploadVars['token'] = $array_["query"]["pages"][key($array_["query"]["pages"])]["edittoken"];
$snoopy->set_submit_multipart();
echo "<br/>";
if(!$snoopy->submit($api_url, $uploadVars))
echo "UPLOAD DENIED";
else
echo "UPLOAD OK";
echo "<br/>";
$array_ = unserialize($snoopy->results);
echo "<br/>-----------<br/>";
print_r($array_);
echo "<br/>.....................<br/>";
echo $snoopy->results;
echo "<br/>-----------";
The execution of this code produce the output bellow:
GOT TOKEN
UPLOAD OK
-----------
.....................
-----------
It's supposed I should receive something like this in the last step:
<api>In fact, nothing really happen, no file is uploaded (the file exists).
<upload result="Success" filename="Test.txt">
<imageinfo timestamp="2000-01-01T00:00:00Z" user="127.0.0.1" anon="" size="1000" width="0" height="0" url="http://localhost/images/3/35/Test.txt" descriptionurl="http://localhost/index.php/File:Test.txt" comment="" sha1="b8f32ebbf9512d8641d7e72c86614c2cee3e8108" metadata="" mime="text/plain" bitdepth="0" />
</upload>
</api>