Results 1 to 8 of 8
  1. #1
    Join Date
    May 2009
    Posts
    11
    Plugin Contributions
    0

    Default 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

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Restrict Maximum Image upload file size ?

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

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    May 2009
    Posts
    11
    Plugin Contributions
    0

    Default 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.

  4. #4
    Join Date
    May 2009
    Posts
    11
    Plugin Contributions
    0

    Default 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.

  5. #5
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Restrict Maximum Image upload file size ?

    It already does that:
    Code:
          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;
          }
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    May 2009
    Posts
    11
    Plugin Contributions
    0

    Default 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.

  7. #7
    Join Date
    May 2009
    Posts
    11
    Plugin Contributions
    0

    Default 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

    Code:
          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

    I hope it may help others too

  8. #8
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Restrict Maximum Image upload file size ?

    If it works for you, great.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. v154 Maximum file size
    By jenpen in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 29 May 2015, 05:41 AM
  2. Define Pages Editior - Maximum File Size?
    By limelites in forum General Questions
    Replies: 13
    Last Post: 29 Jun 2011, 04:36 PM
  3. Replies: 8
    Last Post: 22 May 2010, 04:47 PM
  4. File Upload Attribute - File Size Limit?
    By Genevieve in forum General Questions
    Replies: 2
    Last Post: 4 May 2010, 06:33 PM
  5. Maximum file size for uploads
    By benjames in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 22 Oct 2006, 08:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg