Title: Limiting image uploads
Last modified: May 22, 2019

---

# Limiting image uploads

 *  Resolved [bdd](https://wordpress.org/support/users/bws-online/)
 * (@bws-online)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/limiting-image-uploads/)
 * 1. I’m trying to limit the upload size for images. I used the Limit File Uploads
   snippet as directed here: [https://wordpress.org/support/topic/image-upload-size-2/](https://wordpress.org/support/topic/image-upload-size-2/)
   but it didn’t work.
 * It let the large file get uploaded to the media library. The image shown on the
   ad itself is smaller — is it looking at that file size instead of the one uploaded
   to the library?
 * Is there something else to adjust for this?
 * 2. Also, when more than one image is uploaded on a single ad, is the limit for
   each individual image or for all the images combined?
 * 3. Finally, if I want to change the limit in the snippet from 2MB to something
   less than 1MB, do I list it as a decimal (like 0.5MB) or do I switch to K or 
   KB (and if so, which)?
 * Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/limiting-image-uploads/#post-11562992)
 * 1. i am not sure what do you mean.
    2. in the Limit File Uploads snippet there
   are various validators some apply to individual images like the image size and
   dimensions and some apply to all of the like min and max files uploaded. 3. enter
   500kb there
 *  Thread Starter [bdd](https://wordpress.org/support/users/bws-online/)
 * (@bws-online)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/limiting-image-uploads/#post-11566419)
 * I used the snippet like this:
 *     ```
       function limit_file_uploads( $form ) {
   
           if( $form['name'] != "advert" ) {
               return $form;
           }
   
           foreach( $form["field"] as $key => $field ) {
               if( $field["name"] != "gallery" ) {
                   continue;
               }
   
               $form["field"][$key]["validator"] = array();
   
   
               // Set minimum and maximum file upload size.
               // Note. this is a limit for an individual file, not whole gallery field.
               $form["field"][$key]["validator"][] = array(
                   "name" => "upload_size",
                   "params" => array( 
                       "min" => null,     // minimum file size
                       "max" => "200KB"     // maximum file size
                   )
               );
           }
   
           return $form;
       }
       ```
   
 * I added an image on an ad that was 5.70MB — it allowed that. When I view the 
   image in the ad itself, it shows an image with an intrinsic size of 5312×2988
   pixels at 878×494 pixels. If I look in the Media Library, there’s an image with
   that intrinsic size that’s 6MB. It did not stick to my 200KB max as in the snippet.
 * NOTE: There are 2 other images there, too, even though I removed them from the
   ad before publishing. Shouldn’t it delete images that weren’t used in the final
   ad? Can that be revised so it happens?
 *  Thread Starter [bdd](https://wordpress.org/support/users/bws-online/)
 * (@bws-online)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/limiting-image-uploads/#post-11572195)
 * Making progress!!
 * I cleaned up some revisions and went back to the original Limit File Uploads 
   snippet from GitHub — all good regarding the max limit getting followed.
 * Do you want a new ticket regarding the NOTE on the last post?
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/limiting-image-uploads/#post-11574841)
 * If you removed the images in the [adverts_add] went to the preview and published
   the Ad then the images should not be there in the published Ad.
 * Maybe there was some kind of error when deleting the images due to customizations
   being made in the file upload, can you replicate this problem?
 *  Thread Starter [bdd](https://wordpress.org/support/users/bws-online/)
 * (@bws-online)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/limiting-image-uploads/#post-11576750)
 * They weren’t in the published ad, but they WERE in the Media Library. I did more
   testing now, though — it’s fine. Thanks.
    -  This reply was modified 6 years, 11 months ago by [bdd](https://wordpress.org/support/users/bws-online/).

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Limiting image uploads’ is closed to new replies.

 * ![](https://ps.w.org/wpadverts/assets/icon-256x256.png?rev=2423472)
 * [WPAdverts - Classifieds Plugin](https://wordpress.org/plugins/wpadverts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpadverts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpadverts/)
 * [Active Topics](https://wordpress.org/support/plugin/wpadverts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpadverts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpadverts/reviews/)

## Tags

 * [image size](https://wordpress.org/support/topic-tag/image-size/)
 * [limit](https://wordpress.org/support/topic-tag/limit/)

 * 5 replies
 * 2 participants
 * Last reply from: [bdd](https://wordpress.org/support/users/bws-online/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/limiting-image-uploads/#post-11576750)
 * Status: resolved