[英]How to create a Data base row in Wordpress for uploaded objects to Amazon S3?
在我的 Wordpress 网站中,用户可以将视频文件直接上传到 Amazon S3 存储桶(因此文件不会通过我的网络服务器。)我应该如何跟踪添加的对象(即:我应该在何处以及如何添加数据条目我的 Wordpress 数据库)
通过提供的有限信息,您可以使用 ajax 发布图像数据。 下面是带有图像占位符数据的简单ajax。
var imgData = {author: 'the-author-id', img_url: 'the-url', img_type: 'the-img-type'}
$.ajax({
data : JSON.stringify(imgData),
contentType : 'application/json',
type : 'POST',
url: 'your-wordpress-post-url',
success: function () {
// do something with the success result from backend
}
});
在 WordPress 中,您将使用wp_insert_attachment()
<?php
// Prepare an array of post data for the attachment.
$attachment = array(
'post_author' => $_POST['author'],
'post_date' => current_time('mysql'),
'guid' => $_POST['img_url'],
'post_mime_type' => $_POST['img_type'],
'post_title' => preg_replace( '/\.[^.]+$/', '', $_POST['img_url'] ),
'post_content' => '',
'post_status' => 'inherit',
'comment_status' => 'closed',
'ping_status' => 'closed',
);
// Insert the attachment.
$attach_id = wp_insert_attachment( $attachment );
// if fail $attach_id is 0
echo json_encode(array('attach_id' => $attach_id));
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.