mercredi 29 juin 2016

Wordpress Image upload using xmlrpc get image name

I use xmlrpc for uploading image to my wordpress site. This images only i going use for another mysql table not in post. i use following code

 $rpcurl='http://ift.tt/298qxca';
 $username='admin';
 $password='pass5';
 $blogid=get_current_blog_id(); //Post ID

 $file=file_get_contents('file:///C:/Users/webway/Desktop/ff/2.jpg');
 $filetype = "image/jpeg";
 $filename = "remote_filename.jpg";

xmlrpc_set_type($file,'base64'); // <-- required!
$params = array($blogid,$username,$password,
array('name'=>$filename,'type'=>$filetype,'bits'=>$file,'overwrite'=>false));

$wpdb->insert('wp_bwbps_images', array('image_name' => $filename,'user_id' => '1','gallery_id' => '4'));            

$request = xmlrpc_encode_request('wp.uploadFile',$params);

$result = go($request,$rpcurl);
print_r($result);

function go($request,$rpcurl){
   $ch = curl_init();
   curl_setopt($ch,CURLOPT_POST,1);
   curl_setopt($ch,CURLOPT_URL,$rpcurl);
   curl_setopt($ch,CURLOPT_POSTFIELDS,$request );
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
   $result = curl_exec($ch);
}

After upload i insert image name to another table

$wpdb->insert('wp_bwbps_images', array('image_name' => $filename,'user_id' => '1','gallery_id' => '4'));   

Problem is i also enabled 'overwrite'=>false . so if image name is same upload saveed as image_1.jpg like this

What i need is after image upload i need get saved file name using xmlrpc.php so only i can add that file name in to my custum table..

Any other way?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire