It's possible to have an option to set the max image size for image attach??

Something like Upload module. When you leave the user to post images... could be a seriuos problem.

Comments

Dret’s picture

Excuse me.. I mean "max image FILE size".

niek_kloots’s picture

Dret’s picture

I have tryed this option but it didn't works... I set a limit in upload module and image module... but image_attach still ignore that settings...

Ideas about...??

I'm not skilled in php but in attach_image_module don't seems to be present a function that operate a control upon the attached image... (but probably I'm wrong!)...

Finally... could be a problem to have a single option to set a limit for all unploading file... maybe a dedicated one to this module could be usefull...

Thanks...

niek_kloots’s picture

You're right it didn't work for me also. I just uploaded 2MB where the maximum upload size is 1 MB.

This category should be relocated to bug instead of feature request.

Dret’s picture

Category: feature » bug

Do it!

Finally: it's possible to have an own "file size" limit for image_attach or, in alternative, to use the one already set in main image module settings?

Thanks!
Bye

joachim’s picture

Title: An option to select "max image size" for Image Attach » image attach ignores image module's maximum sizes
Version: 6.x-1.0-alpha4 » 6.x-1.x-dev

Confirming with CVS code -- I set image module's file size limit to 20kb, and then image attach nicely let me attach a new image of 37kb... this is a pretty major hole!

problue solutions’s picture

this is a huge problem for me, I rely entirely on users attaching images, larger images are causing errors and blank pages so it needs to be validated if an image is too large by means of a message to the user instead of just ignoring the max size and causing errors.

any ideas when this is likely to be fixed?

joachim’s picture

Well... someone needs to write a patch. I plan to, but obviously if anyone beats me to it then I get to spend more time working on views support for this module :)
Then the patch needs to be tested so it can be committed.
Given the importance of this issue, I would say some tests could do to be written too -- one for image.module and one here, both checking the max filesize is respected.

joachim’s picture

Component: image_attach » image.module

I had a hunch... from a reading of the code, image_import suffers from the same problem.
Not as severe in its effects in a way, as you'd expect admins using image import to know what they are doing, although an admin might expect the import process to check these things too.

I would say the fault actually lies with image module itself -- image_create_node_from() should check the filesize of the imagefile it is given.

This wouldn't be a be hugely complex patch if you wanted to have a go, thiokol -- drupal documentation has sections on getting a CVS copy and making a patch if you're feeling adventurous :)
See how image_max_upload_size is being checked, and do the same kind of thing in image_create_node_from(), returning FALSE if it's too big. You can mostly frankencode it :p

problue solutions’s picture

I havent written any php in years so I think it would be a bigger task than you'd imagine from my point of view :)

Guess I'll just have to be patient until someone else has the time to do it.

problue solutions’s picture

Is there any intention to fix this? Its a big problem and surely not that difficult to fix (for a developer)

joachim’s picture

Status: Active » Needs review
StatusFileSize
new1012 bytes

Here is a patch.
Please could you test it?

All it does is check the filesize and doesn't create the image if it's too big. It's using drupal_set_message to give a warning because that's the only way of getting feedback out of image_create_node_from().

I think two subsequent issues should be filed
- a test for this function for image filesize
- look at some way of getting error messages out of image_create_node_from().

joachim’s picture

StatusFileSize
new1008 bytes

Better patch: uses form_set_error to prevent form validation.
The message isn't set to a particular form control because we don't have that information to hand: see http://drupal.org/node/424258 -- but that's a relatively minor cosmetic issue.

sun’s picture

Status: Needs review » Needs work

We should pass NULL instead of '' for $name. Also, there is a small grammar mistake in the error message.

joachim’s picture

What's the grammar mistake? I'm not seeing it...

I guess 'you have uploaded' could seem incorrect, as we're preventing the upload.
A comma before 'but'?

joachim’s picture

Status: Needs work » Fixed
StatusFileSize
new1.01 KB

Committed the attached patch with the change in parameter for form_set_error.
Still no idea what sun meant by the grammar error ;)

joachim’s picture

@sun: Did you really mean to pass NULL to form_set_error()? Because it does nothing at all if you do that.

Reversed the previous patch and applied the one from #13.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

joachim’s picture

Missed a bit:


// Ensure the file is within our size bounds.
if ($image_info['file_size'] > variable_get('image_max_upload_size', 800) * 1024) {
form_set_error('', t('The image you uploaded was too big. You are only allowed upload files less than %max_size but your file was %file_size.', array('%max_size' => format_size(variable_get('image_max_upload_size', 800) * 1024), '%file_size' => format_size($file->filesize))), 'warning');
return FALSE;
}

Size doesn't get shown.
Will fix once I am not working on three patches at once.

joachim’s picture

Status: Closed (fixed) » Active
joachim’s picture

Status: Active » Fixed

Fixed.

Status: Fixed » Closed (fixed)
Issue tags: -image attach, -max file size, -upload image

Automatically closed -- issue fixed for 2 weeks with no activity.