Jump to content
PWaddict

How to set maximum image files upload at once with hook?

Recommended Posts

 I'm trying to set maximum image files per upload with the following hook:

$wire->addHookBefore('InputfieldImage::render', function(HookEvent $event) {

 $inputfield = $event->object;
 $inputfield->setMaxFiles(20);

});

but when I go to edit a page with Images fields I'm getting the following error:

ProcessWire: ProcessPageEdit: Method InputfieldImage::setMaxFiles does not exist or is not callable in this context

 

Share this post


Link to post
Share on other sites
3 minutes ago, Zeka said:

@PWaddict Try to use 


$inputfield->set('maxFiles', 20);

This just sets field to accept ONLY 20 images. What I'm looking for is let the editor upload 20 images per upload. If he wants to upload 50 images I don't want to let him upload them all at once.

Share this post


Link to post
Share on other sites

Unless maxFiles & setMaxFiles are actually the same? I've read somewhere that setMaxFiles is max allowed files per upload.

Share this post


Link to post
Share on other sites
1 hour ago, PWaddict said:

What I'm looking for is let the editor upload 20 images per upload. If he wants to upload 50 images I don't want to let him upload them all at once.

Sorry, I don't understand what you are trying to do 🙂 20 + 20 + 10 would work? What is the reason for that request? What is "one upload"? I think you need to be more precise to get better answers.

Share this post


Link to post
Share on other sites
46 minutes ago, bernhard said:

Sorry, I don't understand what you are trying to do 🙂 20 + 20 + 10 would work? What is the reason for that request? What is "one upload"? I think you need to be more precise to get better answers.

My php default shared server settings have max_file_uploads = 20 so I would like to limit to 20 in ProcessWire too cause if I upload for example 30 images at once only the 20 will be uploaded. The other 10 will look like they're uploading forever and this is confusing for the editors. So, is it possible to limit it to 20 in ProcessWire or should I increase the number of max_file_uploads? Also, If I increase it wouldn't be bad for the server performance?

Like with "setMaxFilesize" you're getting a warning on ProcessWire that you're not allowed for example to upload a file with size more than what you've set in "setMaxFilesize", I wanna do the same thing for the maximum files the editor can upload at once. I wanna let him upload max 20 and when those 20 uploaded he should be able to upload 20 max more and so on.

Share this post


Link to post
Share on other sites

Ok something else is going on. On localhost where PHP has max_file_uploads = 20 too (same as live server) I tried to upload 22 images at once and it worked fine. On live server when I tried to upload the same 22 images I got 13 identical errors in chrome console and 13 images stuck at "uploading" forever...

Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR

 

Share this post


Link to post
Share on other sites
3 hours ago, PWaddict said:

On localhost where PHP has max_file_uploads = 20 too (same as live server) I tried to upload 22 images at once and it worked fine.

That's because the file input field uses ajax requests for the files. So each request only holds a single file.

  • Like 1

Share this post


Link to post
Share on other sites

Now, I'm getting more errors besides the one I mention above. You can delete this topic and if I can't figured out the problem I will create a new proper topic with all the details.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...