wp_generate_attachment_metadata gives me an empty array

From comment:

Let WordPress generate a file path and use that for the next steps:

$upload    = wp_handle_upload($filename, array('test_form' => false));
$attach_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
wp_update_attachment_metadata( $attach_id,  $attach_data ); 

Leave a Comment