Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
    
in terms of never being able to 'regenerate' thumbnails since you need the original, is there a way to rename the 'large' image so that it is seen as the original? ie you'd have image100x100.jpg, image300x300.jp and image.jpg (where the last one is maxed out a the 'large' dimensions –  helgatheviking Feb 27 '12 at 14:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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