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?

1 Answer 1

This is how you can limit the image upload size

function fineima() {
  if (isset($_POST['submit'])) {
    wp_upload_bits($_FILES['fileToUpload']['name'], null, file_get_contents($_FILES['fileToUpload']['tmp_name']));
  echo '<form action="" method="post" enctype="multipart/form-data">
      <input type="file" name="fileToUpload" id="fileToUpload">
      <input type="submit" value="Upload Image" name="submit">
function fineFileUploaderRenderer() {
  return ob_get_clean();
add_shortcode('your_file_uploader', 'fineFileUploaderRenderer');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.