Page 1 of 1

xmlrpc-bug: adding pictures don't work

Posted: Mon Jan 17, 2005 8:02 pm
by bigger4you
Hello,

I found a bug in uploading an image per xmlrpc. The upload fails if in struct['name'] is a subdirectory included eg. '2005-01-17/picture.jpg'

I have solved this problem for me in the following file serendipity_xmlrpc.php and have implemented a directory check:

Code: Select all

function metaWeblog_newMediaObject($message) {
    global $serendipity;
    $val = $message->params[0];
    $postid = $val->getval();
    $val = $message->params[1];
    $username = $val->getval();
    $val = $message->params[2];
    $password = $val->getval();
    $val = $message->params[3];
    $struct = $val->getval();
    if (!serendipity_authenticate_author($username, $password)) {
        return new XML_RPC_Response('', 4, 'Authentication Failed');
    }
    // Check if Directory exists
    if (!is_dir(dirname($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $struct['name']))) {
         mkdir(dirname($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $struct['name']));
    }
    // End
    $fp = fopen($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $struct['name'], 'w');
    fwrite($fp, $struct['bits']);
    fclose($fp);
    $path = $serendipity['baseURL'] . $serendipity['uploadPath'] . $struct['name'];
    return new XML_RPC_Response(new XML_RPC_Value(array('url' => new XML_RPC_Value($path, 'string')), 'struct'));
}
Hope this helps you.

Kind Regards
Heinz Stampfli
heinz.st [at] mpf.li

Re: xmlrpc-bug: adding pictures don't work

Posted: Mon Jan 17, 2005 8:16 pm
by garvinhicking
Thanks a lot!

I committed your patch to CVS!

Regards,
Garvin