一个特定的API,返回数据中的二进制图像。
如果我需要将它保存到服务器,我可以通过遵循代码轻松地完成它。
$response = curl_exec($curl); // This is the API response
file_put_contents('example2.png', $response);
如何将其添加到WordPress媒体库?
发布于 2023-02-06 18:37:26
您应该使用media_handle_sideload
。将您的文件写入文件系统,然后使用media_handle_sideload
处理它,就像处理任何其他上传一样。以后一定要清理干净。
参见:https://developer.wordpress.org/reference/functions/media_手柄_副业/#评论-983中的一个示例
https://wordpress.stackexchange.com/questions/413581
复制相似问题