wp_upload_bits Upload Specific Sizes Only
For images uploaded using this code, I want to only upload the full-size image and the thumbnail (whereas for images uploaded through site, I want all sizes). However, I can’t figure out how to make it only upload the full-size/thumbnail as this code currently only uploads an image with all sizes:
$attachment = array( 'post_author' => "test", 'post_date' => $date, 'post_date_gmt' => gmdate('Y-m-d H:i:s', strtotime($date) ), 'post_title' => "just some title", 'post_status' => 'inherit', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_name' => "just some picture", 'post_modified' => $date, 'post_modified_gmt' => gmdate('Y-m-d H:i:s', strtotime($date) ), 'post_type' => 'attachment', 'guid' => $upload['url'], 'post_mime_type' => $wp_filetype['type'], 'post_excerpt' => '', 'post_content' => '' ); $upload = wp_upload_bits( "picture.jpg", null, file_get_contents("picture.jpg") ); if ( $upload['error'] ) echo "Failed uploading: " . $upload['error'];
The only way I can think of doing this is to return the
attachment_id and then
unlink all sizes except the full size and the thumbnail, but that seems very messy. What is the way to do this?