Recent Topics

envoi d'image par un client blog

started by on Sep 28, 2011 – Last touched: Sep 28, 2011

Sep 28, 2011 13:28    

Bonjour

je n'arrive pas a uploader des images par le biais de client blog (ecto, scribefire,..) et ceci quelque soit le choix de l'api (MT, Movable, Wordpress)
je subodore un pb de droit mais je ne sais comment le résoudre

merci de votre aide

Sep 29, 2011 01:31

Quelle version de b2evolution?

Sep 29, 2011 10:26

Version 4.0.4

j'ai trouvé : j'ai copié les lignes d'une ancienne API pour l'upload de fichier (prise sur la version 2) et cela fonctionne à nouveau.

{
global $xmlrpcerruser; // import user errcode value
global $Settings, $baseurl,$fileupload_allowedtypes;

// CHECK LOGIN:
/**
* @var User
*/
if( ! $current_User = & xmlrpcs_login( $m, 1, 2 ) )
{ // Login failed, return (last) error:
return xmlrpcs_resperror();
}

// GET BLOG:
/**
* @var Blog
*/
if( ! $Blog = & xmlrpcs_get_Blog( $m, 0 ) )
{ // Login failed, return (last) error:
return xmlrpcs_resperror();
}

// CHECK PERMISSION:
// For lack of more subtle perm: require any edit perm on blog + global file add perm.
if( ! $current_User->check_perm( 'blog_post_statuses', 'edit', false, $Blog->ID )
|| ! $current_User->check_perm( 'files', 'add', false ) )
{ // Permission denied
return xmlrpcs_resperror( 3 ); // User error 3
}
logIO( 'Permission granted.' );

if( ! $Settings->get('upload_enabled') )
{
return new xmlrpcresp(0, $xmlrpcerruser+2, // user error 2
'Object upload not allowed ');
}

$xcontent = $m->getParam(3);

// Get the main data - and decode it properly for the image - sorry, binary object
$contentstruct = xmlrpc_decode_recurse($xcontent);

$data = $contentstruct['bits'];

$type = $contentstruct['type'];
logIO( 'Received MIME type: '.$type );

$rf_filepath = $contentstruct['name'];
logIO( 'Received filepath: '.$rf_filepath );
// Avoid problems:
$rf_filepath = strtolower($rf_filepath);
$rf_filepath = preg_replace( '¤[^a-z0-9\-_./]¤', '-', $rf_filepath);
logIO( 'Sanitized filepath: '.$rf_filepath );

load_funcs('files/model/_file.funcs.php');

// Split into path + name:
$filepath_parts = explode( '/', $rf_filepath );
$filename = array_pop( $filepath_parts );

// Check valid filename/extension: (includes check for locked filenames)
logIO( 'File name: '.$filename );
if( $error_filename = validate_filename( $filename, false ) )
{
return new xmlrpcresp(0, $xmlrpcerruser+4, // user error 4
'Invalid objecttype for upload ('.$filename.'): '.$error_filename);
}

// Check valid path parts:
$rds_subpath = '';
foreach( $filepath_parts as $filepath_part )
{
if( empty($filepath_part) || $filepath_part == '.' )
{ // self ref not useful
continue;
}

if( $error = validate_dirname($filepath_part) )
{ // invalid relative path:
logIO( $error );
return new xmlrpcresp(0, $xmlrpcerruser+3, // user error 3
$error );
}

$rds_subpath .= $filepath_part.'/';
}
logIO( 'Subpath: '.$rds_subpath );

$fileupload_path = $Blog->get_media_dir();
if( ! $fileupload_path )
{
return new xmlrpcresp(0, $xmlrpcerruser+5, // user error 5
'Error accessing Blog media directory.');
}

// Create subdirs, if necessary:
if( !empty($rds_subpath) )
{
$fileupload_path = $fileupload_path.$rds_subpath;
if( ! mkdir_r( $fileupload_path ) )
{ // Dir didn't already exist and could not be created
return new xmlrpcresp(0, $xmlrpcerruser+6, // user error 6
'Error creating sub directories: '.rel_path_to_base($fileupload_path));
}
}

$afs_filepath = $fileupload_path.$filename;
logIO( 'Saving to: '.$afs_filepath );
$fh = @fopen( $afs_filepath, 'wb' );
if( !$fh )
{
logIO( 'Error opening file' );
return new xmlrpcresp(0, $xmlrpcerruser+7, // user error 7
'Error opening file for writing.');
}

$ok = @fwrite($fh, $data);
@fclose($fh);

if (!$ok)
{
logIO( 'Error writing to file' );
return new xmlrpcresp(0, $xmlrpcerruser+8, // user error 8
'Error while writing to file.');
}

// chmod uploaded file:
$chmod = $Settings->get('fm_default_chmod_file');
logIO( 'chmod to: '.$chmod );
@chmod( $afs_filepath, octdec( $chmod ) );

$url = $Blog->get_media_url().$rds_subpath.$filename;
logIO( 'URL of new file: '.$url );

// - return URL as XML
$urlstruct = new xmlrpcval(array(
'url' => new xmlrpcval($url, 'string')
), 'struct');

logIO( 'OK.' );
return new xmlrpcresp($urlstruct);
}

Sep 30, 2011 17:00

Bon, visiblement c'est soit je peux poster les images, j'ai l'historique mais je n'ai pas le nom des catégorie ou un melange des 3 mais jamais les 3 fonctions en meme temps

y'a t'il une mise a jour de l'API prévue prochainement ?


Form is loading...

powered by b2evolution – This forum is powered by b2evolution CMS, a complete engine for your website.