Agile Uploader Wordpress implementation
Asked Answered
M

2

6

I'm trying to implement a front page Wordpress uploader which gives the user the possibility to upload an image from a Wordpress page and also resizes images before upload. I found Agile Uploader. The uploader is in a form.

The problem is when I click the submit button in the form to send the data, all fields are stored in a post, but the images not.

Here is the code for my upload page:

<form id="submitForm" action="<?php echo get_permalink(); ?>" method="post" enctype="multipart/form-data" onsubmit="return ray.ajax()">
<!-- upload photos -->

  <div style="float:left;width:410px; height:246px;">
    <div id="multiple"></div>
  </div>

  <script type="text/javascript">
    jQuery('#multiple').agileUploader({
      formId: 'submitForm',
      flashVars: {
        file_post_var: 'attachment',
        firebug: false,
        form_action: '',
        file_limit: 15,
        max_post_size: (1000 * 1024)
      }
    }); 
  </script>

  </div>   <!-- end - upload photos -->
</form>

and the code for Wordpress upload (it`s in the same file)

/* upload photos */
if ($post_error == false) {

  /* required files */
  require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  require_once(ABSPATH . "wp-admin" . '/includes/media.php');

  $files = $_FILES['attachment'];

  if ($files) { 

    foreach ($files['name'] as $key => $value) {
      if ($files['name'][$key]) {
        $file = array(
          'name' => $files['name'][$key],
          'type' => $files['type'][$key],
          'tmp_name' => $files['tmp_name'][$key],
          'error' => $files['error'][$key],
          'size' => $files['size'][$key]
        );  
      }

      $_FILES = array("attachment" => $file);
      //$_FILES = array_reverse($_FILES);
      foreach ($_FILES as $file => $array) {                                  
        $attach_id = media_handle_upload( $file, $ad_id, array(), array( 'test_form' => false ) );
        if ($attach_id < 0) { $post_error = true;
      }
    }
  }
}

What am I doing wrong?

Monogamist answered 12/12, 2012 at 13:29 Comment(2)
So the problem is the saving of the entire form?Moulding
any error messages?, check in your firebug console and post to here to get quick answerKanzu
C
0

Are you sure that the images are not saved as an 'Attachment' to the created post?

Try running:

$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude'     => get_post_thumbnail_id()) 
);
var_dump($attachments);

In the template file you use to view the post. If you're not comfortable with coding, you might use a plugin to do show attached files. Like this "List Attachments Shortcode" plugin.

Contrition answered 22/7, 2013 at 10:1 Comment(0)
I
0

This might be a little simple, and may not be your issue, but you are missing a curly brace ending (}) after if ($attach_id < 0) { $post_error = true;.

Is that in your actual code or did you simply forget to put it in to your question above?

Isis answered 20/6, 2015 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.