Delete the original big size image after upload and leave only 3 images crunched by media gallery

I need to know is it possible to somehow erase the original image uploaded via Gravity form : post image – post field?! With the situation now I receive 4 images. 1 original (can be whatever user has on his PC – up to 4 MB which clutters the server) and 3 which WordPress creates according to specifications (thumbnail, medium, large). I would like to have the ability when user uploads the “original big image” to be deleted upon upload and be left with 3 remaining in media gallery?!. It will dramatically improve the storage on my server.

Cheers!

Related posts

Leave a Reply

1 comment

  1. How about this:

    add_filter( 'wp_generate_attachment_metadata', 'delete_fullsize_image' );
    function delete_fullsize_image( $metadata )
    {
        $upload_dir = wp_upload_dir();
        $full_image_path = trailingslashit( $upload_dir['basedir'] ) . $metadata['file'];
        $deleted = unlink( $full_image_path );
    
        return $metadata;
    }
    

    Not 100% sure everything will work ok without the main image, but it does the trick. You wont be able to regenerate the thumbnails / sizes as the main image is required for this.

    Edit: I just re-read the question, I noticed you are wanting this to only happen when people upload via a form. Must be early for me, the above code will delete any attachment uploaded. I guess all you would need to do is find someway of checking if the upload was via your gravity form. Hope it helps you anyway.