[wp-hackers] Re: Reject uploaded image

scribu scribu at gmail.com
Mon Jan 26 15:00:06 GMT 2009


>
> I'm trying to do something like this:
>
> A user uploads an image. If the image resolution is lower than 640x480px
> (for example), then an error message is sent to the user and the image is
> deleted.
>
> I've tried using *add_action('media_upload_image', 'my_function')*, but
> that doesn't help.
>
> Maybe using *add_filter('async_upload_image', 'my_function')* ?
>
> Any ideas?
>

I've found that using add_attachment doesn't work because the metadata is
generated after that, so I did it like this:


    add_filter('wp_update_attachment_metadata', 'check_size', 10, 2);

    public function check_size($data, $id) {
        if ( $data['width'] < 800 && $data['height'] < 600 ) {
            wp_delete_attachment($id);
            echo "<strong class='error'>Error: Image too small</strong>";
        }
    }


-- 
http://scribu.net


More information about the wp-hackers mailing list