xmlrpc-bug: adding pictures don't work

Found a bug? Tell us!!
Post Reply
bigger4you

xmlrpc-bug: adding pictures don't work

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

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

Post by garvinhicking »

Thanks a lot!

I committed your patch to CVS!

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply