Skip Navigation

[Resolved] Limit Number of Files a User Can Upload

This support ticket is created 3 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by Clayton Chase 3 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2115685

Is it possible to limit the total number of files a user can upload? I've implemented code which is working to hide the "Add more" button but I'm wondering about limiting the number of files a user can upload through the WordPress uploader. Is that possible or do you have any suggestions on how to achieve that?

#2116391

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand you are using media uploader to upload the images and you want to limit the number of files to be uploaded in backend or using Toolset forms?

#2116603

Yes, that is correct. The issue I'm having is that a user can upload unlimited images since the WordPress media manager allows for multiple uploads at one time – even if I limit the number of repeater fields they can add via the jQuery I've added.

#2118529

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As you are using the Media uploader there is no easy way to check.

Can you please try to check the following code and see if that helps:
- hidden link

OR

You can use the server side validation hook - cred_form_validate, please check if that helps:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

If you want to use the repeating field to upload image - then you can restrict it using JS, here is reference ticket.
- https://toolset.com/forums/topic/limit-number-uploading-files/#post-335393

#2119235

I tried the code you suggested here (hidden link) but it didn't seem to work. Any help refining that code might help.

I've already implemented the last suggestion you made but the issue is that when the multi-instance option is turned on you can upload as many images as you want even if you can only add six instances of a field.

#2119627

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've already implemented the last suggestion you made but the issue is that when the multi-instance option is turned on you can upload as many images as you want even if you can only add six instances of a field.
==>
Regarding this, what if we hide :Add New button once user reach to 6th instance of the repeating field?

Or you are saying even if we hide the "Add New" button after six instance but using media uploader users are still able to upload multiple images?

#2119943

Yes, "Or you are saying even if we hide the "Add New" button after six instance but using media uploader users are still able to upload multiple images?" is exactly what is happening. Even though the "Add new" button is limited to 6 the user can upload as many media files as they want through the wordpres media manager.

We are trying to avoid this to keep the number of files smaller instead of letting users just upload as many as they want.

#2119961

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Toolset uses the WordPress standard media uploader and I do not think if media uploader offers any limits.

As of now I do not have any workaround or solution to offer you, if you stop using media uploader then I will have a solution for you or you will have to wait a bit and allow me some time to find workaround (if possible) as I need to debug big deep but I do not promise that I will have a solution to offer. I will just give a try when I get some time. Let me know if that is OK for you.

#2119977

Hey Minesh,

Thank you for your response. That sounds great and I totally understand that it is a WordPress limitation. I appreciate your help.

#2125109

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I tried to devote some time but unfortunately I do not have any workaround to offer at the moment.

When I see its only ask to use the following filter: wp_handle_upload_prefilter
=> https://wordpress.stackexchange.com/questions/21084/how-can-you-limit-the-number-of-images-videos-that-can-be-uploaded-to-a-wordpr

Can you please check the code snippet offered on the above link and check if that helps.

#2126883

Thanks Minesh! I think I found a plugin (hidden link) that might work. I'm going to be doing some testing. I appreciate you looking in to this.