Ask your WordPress questions! Pay money and get answers fast! (more info)

Gravity Forms Multi File Upload WordPress

  • REFUNDED

Hi, I'm trying to write something that allows for a multiple file upload on a Gravity Form using the List field.

Example form (please don't submit if you don't have to): http://ktrusak.com/new-gallery/

Current Code I tried:

function insert_attachment($file_handler,$post_id,$setthumb='false') {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload( $file_handler, $post_id );
if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
return $attach_id;
}

add_filter("gform_after_submission_14", "my_add_post_attachements", 10, 3);
function my_add_post_attachements($entry, $form) {

$post_id = $entry["post_id"];

if ( $_FILES ) {
$files = $_FILES['input_2'];
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("input_2" => $file);

foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$post_id);
}
}
}
}
}

Answers (1)

2013-09-10

Romel Apuya answers:

so whats the question???


Kyle comments:

Code doesn't work