i am doing a entrance finish put up submission for a CPT referred to as "empresas" and with CMB2 i create a customized subject referred to as portfolio which sort is file_list so the enterprise can add their work
In my customized kind i’ve a enter single file to add the corporate brand and different enter file a number of for add their work
I am utilizing the next code to add the emblem as a featured picture for put up and works with none drawback
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, $post_id );
var_dump($attach_id);
}
}
if($attach_id > 0) {
update_post_meta( $post_id,'_thumbnail_id', $attach_id );
}
The issue is when i add the enter a number of file and the code, it dosen’t add any picture, i attempted this code doing somewhat modification however is not working
The code for add the a number of file is
$otherfiles = $_FILES['trabajos_empresa'];
foreach ( $otherfiles['name'] as $key => $worth ) {
if ( $otherfiles['name'][ $key ] ) {
$file = array(
'identify' => $otherfiles['name'][ $key ],
'sort' => $otherfiles['type'][ $key ],
'tmp_name' => $otherfiles['tmp_name'][ $key ],
'error' => $otherfiles['error'][ $key ],
'dimension' => $otherfiles['size'][ $key ],
);
$_FILES['trabajos_empresa'] = $file;
$attachment_id = media_handle_upload( 'trabajos_empresa', $post_id );
update_post_meta( $post_id,'_studiare_portafolio', $attachment_id );
var_dump($attachment_id);
if ( is_wp_error( $attachment_id ) ) {
// There was an error importing the picture.
echo 'Error including file';
} else {
// The picture was uploaded efficiently!
//Echo to see if picture add nice
echo 'File added efficiently with ID: ' . $attachment_id . '<br>';
echo wp_get_attachment_image( $attachment_id, array( 800, 600 ) ) . '<br>'; // Show the uploaded picture with a dimension you would like. On this case it's 800x600
}
}
}
And the html im utilizing is
<enter sort="file" identify="post_image" id="post_image" aria-required="true">
<enter sort="file" identify="trabajos_empresa[]" id="trabajos_empresa" aria-required="true" a number of="multiple">
if i do a var_dump i get all of the information uploaded within the enter trabajos_empresa however nothing is save in my media gallery