$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>media - Upload images with comment|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

media - Upload images with comment

matteradmin14PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 2

EDIT: 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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far