Multiple File Upload with HTML 5 and PHP -
i'm trying upload multiple files , attach them wordpress post. code works great single images:
php
function insert_attachment($file_handler,$post_id,$setthumb='false') { // check create sure successful upload if ($_files[$file_handler]['error'] !== upload_err_ok) __return_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); homecoming $attach_id; } if ($_files) { foreach ($_files $file => $array) { $newupload = insert_attachment($file,$pid); }
html
<fieldset class="images"> <label for="images">images</label> <input type="file" name="images" id="images" tabindex="25"/> </fieldset>
but how can create work multiple images?
i know have add together multiple="multiple"
input, name of input should images[]
. definately have problems php script.
in case need in future: found solution here:
// if have files if ( $_files ) { // upload attachment files $files = $_files['upload_attachment']; foreach ($files['name'] $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("upload_attachment" => $file); foreach ($_files $file => $array) { $newupload = insert_attachment($file,$post->id); } } } }
php upload
No comments:
Post a Comment