admin管理员组文章数量:1435859
EDIT: I finally got the right answer; see my own answer beneath this post for everyone that's interested.
After searching for a couple of days and trying over and over again I really got stuck. I've a client who collects customer experiences on his website by using the comment form; all comments are displayed as a customer review. So far so good.
But since it's company does a lot with traveling, he needs to give his customers to upload up to five images with there review.
So what I need to do is find a way to let customers upload media along with there filled in comment form. I do know it's kind of risky, since there could be corrupt images uploaded and so on. But still, I would like to achieve it.
Tried a lot a things but the point where I get stuck over and over again is the file upload handling, for a non-logged-in user which is posted with a comment form...
Any thoughts will be very appreciated!
EDIT: I finally got the right answer; see my own answer beneath this post for everyone that's interested.
After searching for a couple of days and trying over and over again I really got stuck. I've a client who collects customer experiences on his website by using the comment form; all comments are displayed as a customer review. So far so good.
But since it's company does a lot with traveling, he needs to give his customers to upload up to five images with there review.
So what I need to do is find a way to let customers upload media along with there filled in comment form. I do know it's kind of risky, since there could be corrupt images uploaded and so on. But still, I would like to achieve it.
Tried a lot a things but the point where I get stuck over and over again is the file upload handling, for a non-logged-in user which is posted with a comment form...
Any thoughts will be very appreciated!
Share Improve this question edited Jul 25, 2012 at 20:36 Dennis Hunink asked Jul 16, 2012 at 19:38 Dennis HuninkDennis Hunink 1411 silver badge5 bronze badges 3- Hi, welcome to WPSE! Please take a moment to read this site FAQ, 'cause apparently you haven't seached here..;) Although, IMO, that's an exact duplicate, answers there are no longer valid but much probably this one is. – brasofilo Commented Jul 16, 2012 at 20:20
- Sorry, there's an anwer there with an active plugin (freemium and not from the Repository). . . . . . . PS: useful: notification apps for SE: stackapps – brasofilo Commented Jul 16, 2012 at 20:36
- look into this plugin: wordpress/extend/plugins/wordpress-comment-images – Towfiq Commented Jul 17, 2012 at 17:10
1 Answer
Reset to default 2EDIT: With some help of a friend I came up with a solution. For everyone interested: Use a custom post-type, in my case comment_post. Then upload the images like this:
$new_post = array(
'post_title' => $title,
'post_content' => $comment,
'post_status' => 'pending',// Choose: publish, preview, future, draft, etc.
'post_type' => 'comments_post' // Use a custom post type
);
//save the new post and return its ID
$pid = wp_insert_post($new_post);
//Upload the file(s)
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
if ($_FILES) {
foreach ($_FILES as $file => $array) {
//Check if the $_FILES is set and if the size is > 0 (if =0 it's empty)
if(isset($_FILES[$file]) && $_FILES[$file]['size']>0){
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
echo '<div class="allert alert-error"><p>Upload error : ' . $_FILES[$file]['error'] . '</p></div>';
$upload = false;
}else{
$upload = true;
}
if($upload == true){
$attach_id = media_handle_upload( $file, $pid );
}
}
}
}//End if '$_FILES'
}//End if errornumbers
本文标签: mediaUpload images with comment
版权声明:本文标题:media - Upload images with comment 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745667974a2669396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论