Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Restrict Maximum Image upload file size ?

Restrict Maximum Image upload file size ?

Locked

Views: 3,756

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
11 May 2009, 7:55 AM
#1
greentrees avatar

greentrees

New Zenner

Join Date:
May 2009
Posts:
11
Plugin Contributions:
0

Restrict Maximum Image upload file size ?

Is there a way of restricting the maximum file size of an image that can be uploaded when adding a new product in admin / catalogue / categories/products ? I have Image Handler 2 installed on 1.3.8a and wish to prevent raw camera files from being uploaded to force my user to reduce the filesize locally.

I've searched and serached, now hoping my 1st post isn't too dumb ! -Thanks -GT

11 May 2009, 7:56 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Restrict Maximum Image upload file size ?

There are some upload restrictions settings in Admin->Configuration->Maximum Values

11 May 2009, 6:29 PM
#3
greentrees avatar

greentrees

New Zenner

Join Date:
May 2009
Posts:
11
Plugin Contributions:
0

Re: Restrict Maximum Image upload file size ?

Thank you DrByte but I have already tried setting the Maximum File Upload Size to for example 204800 and I can still upload a 3Megabtye .jpg file as a products image via admin / catalogue / categories/products / new product.

Whilst 3Mb images should not be uploaded I wish to actually prevent this to help educate my not so net savvy shop owner.:wink:

12 May 2009, 7:08 PM
#4
greentrees avatar

greentrees

New Zenner

Join Date:
May 2009
Posts:
11
Plugin Contributions:
0

Re: Restrict Maximum Image upload file size ?

Gievn the lack of response perhaps I need to modify the php code to acheive this ? Fairly new to php but wondering if I could simply test for size and add a die() in admin/includes/classes/upload.php

Any thoughts gratefully received.

12 May 2009, 7:10 PM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Restrict Maximum Image upload file size ?

It already does that:```
if (zen_not_null($file['size']) and ($file['size'] > MAX_FILE_UPLOAD_SIZE)) {
if ($this->message_location == 'direct') {
$messageStack->add_session('header', ERROR_FILE_TOO_BIG, 'error');
} else {
$messageStack->add_session('upload', ERROR_FILE_TOO_BIG, 'error');
}
return false;
}

12 May 2009, 7:39 PM
#6
greentrees avatar

greentrees

New Zenner

Join Date:
May 2009
Posts:
11
Plugin Contributions:
0

Re: Restrict Maximum Image upload file size ?

Please forgive me if I'm missing something but that test for filesize is only present in /includes/classes/upload.php but not in admin/includes/classes/upload.php It's the admin side that I wish to restrict in this way.

13 May 2009, 7:42 PM
#7
greentrees avatar

greentrees

New Zenner

Join Date:
May 2009
Posts:
11
Plugin Contributions:
0

Re: Restrict Maximum Image upload file size ?

I've taken the part that tests the uploaded filesize from the shop version /includes/classes/upload.php modified it to suit and added it to the admin version /admin/includes/classes/upload.php. Here is what I've come up with at around line 72

      if ( zen_not_null($file['tmp_name']) && ($file['tmp_name'] != 'none') && is_uploaded_file($file['tmp_name']) ) {
		/*** My added code to restrict product image filesize ***/
	    if (zen_not_null($file['size']) and ($file['size'] > MAX_FILE_UPLOAD_SIZE)) {
          if ($this->message_location == 'direct') {
            $messageStack->add(ERROR_FILE_TOO_BIG, 'error');
          } else {
            $messageStack->add_session(ERROR_FILE_TOO_BIG, 'error');
          }
          return false;
        }
		/*** End added code ***/
        if (sizeof($this->extensions) > 0) {
          if (!in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), $this->extensions)) {
            if ($this->message_location == 'direct') {
              $messageStack->add(ERROR_FILETYPE_NOT_ALLOWED, 'error');
            } else {
              $messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error');
            }

            return false;
          }
        }

It seems to do exactly what I wanted but I would greatly appreciate some thoughts from those more experienced than me:unsure:

I hope it may help others too:smile:

14 May 2009, 2:37 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Restrict Maximum Image upload file size ?

If it works for you, great.