问题描述
我试图将在get请求中捕获的图像保存在服务器上的API上。 经过数小时的尝试,我捕获了数据图像,但没有找到保存它的方法。
这是我的代码:
foreach ($photos as $photo) {
$photo_uuid=$photo['uuid'];
$request = wp_remote_get('https://api.??????.fr/annonces/'.$uuid.'/photos/'.$photo_uuid,array( 'timeout' => 10,'headers' => array( 'AUTH-TOKEN' => '---------------'),'uuid_annonce' => $uuid,'uuid_photo' => $photo_uuid
));
if( is_wp_error( $request ) ) {
return false; // Si il y a une erreur,on s'arrête là
}
$body = wp_remote_retrieve_body( $request );
$src = 'data:image/jpg;base64,'. base64_encode($body);
$data = str_replace('data:image/jpg;base64,','',$src);
$data = str_replace(' ','+',$data);
$data = base64_decode($data);
$file = '<?PHP echo esc_url( home_url( '/' ) ); ?>wp-content/themes/--------/img/'. uniqid() . '.jpg';
file_put_contents($file,$data);
// $re = '<img src="'. $src .'" alt="jpg" />';
// echo $re;
}
对不起,我的英语水平,
谢谢:)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)