I am using front end post with upload image,
my code
if (!function_exists('wp_generate_attachment_metadata')){
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) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload( $file, $new_post );
}
}
if ($attach_id > 0){
//and if you want to set that image as Post then use:
update_post_meta($new_post,'_thumbnail_id',$attach_id);
}
and it’s work good with uploading one image like this
<input type="file" id="image" name="image">
but when I change my html to
<input type="file" id="image" name="image[]" multiple="multiple" >
it stop uploading
Can any one help me please????
the
multiple="multiple"
ormultiple=""
attribute of input file tag is fairly new and not widely supported cross browser but if that is the way you want to go,try this:
now when the files are uploaded you need to use a fix to the array in order to use that function, so use these function from Golden Apples
and once you have this function then you can do this:
which should work