I am using the image.module 4.7.x to have images posted on my site. If a user uploads an image with the image.module that is larger than my php.ini settings (currently 2mb) I get the warning:
The selected file /var/www/files could not be copied.
Subsequently, within my /files/images/ folder this creates files, files_0, files_1, etc... with 0kb file sizes.
Also, a new node is created with just a title (and any body text if it was entered), but no image.
I would like to check the file to be uploaded and if it is larger than my max file size limit I would like to throw an error to the user letting them know the image needs to be scaled down. Also, I don't want a node created if the file size is too large.
I entered this code within the image.module after line 156 without any luck:
// check to see if the file size is less than php.ini max limit
if (filesize($file->filepath) / 1000000 > 2 ) {
//the number "2" is for the number of megabytes
form_set_error($field_name, t('The uploaded image is too large Scale it down under 2 megabytes'));
return;
}
Has anybody got something similar working???
Comments
hook_validate with image.module
Perhaps I should use the hook_validate function within image.module. Not sure how I could do this.
Here's what I have been trying without hook_validate. I'm able to pull the current php.ini max_upload_size using:
Now i need to somehow pull the uploaded image's filesize, but I'm having trouble. Here's what I've tried:
So then I would do:
Does anybody know how to validate the uploaded image and pull it's filesize?
-------------------------------------
CommunityTraveler
Any
Any suggestions/thoughts?
-------------------------------------
CommunityTraveler
Hey v1nce every figure this out out?
Hi v1nce. I've got this exact same problem. It's hard to believe nobody else seems to have a problem with this. Anyway, did you find an answer?
=-=
there is an enhanced scaling module available in the downloads area that should solve this type of problem.
have a look at the image enhanced scaling module
with it you should be able to scale images down automatically after they are uploaded so that you never have empty image files.
I patched the image module
I patched the image module with the below:
line 70:
line 156-162
-----------------------------------------------------------------
Petafoo - We Love Animals