Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15
  1. #11
    Join Date
    Sep 2008
    Posts
    19
    Plugin Contributions
    2

    Default Re: File upload module

    Hey,

    Sorry for the huge delay, I guess you won't see this but others reading may.

    On the site I was using this code for there was only one product that required a file to be uploaded; this product also required a message to be uploaded.

    I've experimented with the site and this code correctly forces all products that have a file upload option to require it PROVIDED THEY HAVE AT LEAST 1 OTHER ATTRIBUTE. I'm guessing you coincidentally also had another attribute on the first product but not on subsequent products.

    I'm not quite sure why this is the case; I'll look into it now.

  2. #12
    Join Date
    Sep 2008
    Posts
    19
    Plugin Contributions
    2

    Default Re: File upload module

    Hi there.

    I believe my above post is correct. I now have this function working on multiple items with no other attributes.

    -- Changes --

    BUGFIX: The file upload is now required on products even if they do not have other attributes.

    -- Instructions --

    !!! IMPORTANT: BACKUP includes/classes/shopping_cart.php !!!

    1) In file includes/classes/shopping_cart.php

    Around Line 1570 find:
    PHP Code:
      function actionAddProduct($goto$parameters) {
        global 
    $messageStack$db;
        
        
        if (isset(
    $_POST['products_id']) && is_numeric($_POST['products_id'])) {
          
    // verify attributes and quantity first
          
    $the_list '';
          
    $adjust_max'false';
          if (isset(
    $_POST['id'])) {
            foreach (
    $_POST['id'] as $key => $value) {
                
    $check zen_get_attributes_valid($_POST['products_id'], $key$value);
                if (
    $check == false) {
                    
    $the_list .= TEXT_ERROR_OPTION_FOR '<span class="alertBlack">' zen_options_name($key) . '</span>' TEXT_INVALID_SELECTION '<span class="alertBlack">' . (zen_values_name($value) == 'TEXT' TEXT_INVALID_USER_INPUT zen_values_name($value)) . '</span>' '<br />';
                }
            }
          } 
    2) -- ONLY REQUIRED IF YOU HAVE FOLLOWED POST #9 --

    If you have followed my instructions in post #9 delete ALL of the text between my BOF and EOF comments including the comments themselves...

    PHP Code:
    /**
        BOF - FORCE FILE UPLOAD (Addition)
        NOTE: Upload limits are now controlled entirely by php.ini (upload_max_filesize & post_max_size) also NOTE: post_max_size MUST be greater than upload_max_filesize
        For this fix to work ensure that Admin > Configuration > Maximum Values > Maximum File Upload Size is GREATER (in bytes) than upload_max_filesize (in MB)
        The Allowed file upload extensions are still controlled by Admin > Configuration > Maximum Values > Allowed Filename Extensions for uploading except a mismatch now prevents the product being added to cart
        **/ 

    .. DELETE ME INCLUDING THE COMMENTS IMMEDIATELY ABOVE AND BELOW ME...

    //EOF - FORCE FILE UPLOAD (Addition) 
    3) -- BUGFIX --

    Being careful to place it in exactly the right place add all of the code shown between the //BOF and //EOF comments in the code below. Note all of the code NOW comes after the opening brace of the line: isset($_POST['products_id'] ... but before the line if (isset($_POST['id']))...

    PHP Code:
    if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
          
    // verify attributes and quantity first
          
    $the_list '';
          
    $adjust_max'false';
          
        
    /**
            BOF - FORCE FILE UPLOAD (Addition)
            NOTE: Upload limits are now controlled entirely by php.ini (upload_max_filesize & post_max_size) also NOTE: post_max_size MUST be greater than upload_max_filesize
            For this fix to work ensure that Admin > Configuration > Maximum Values > Maximum File Upload Size is GREATER (in bytes) than upload_max_filesize (in MB)
            The Allowed file upload extensions are still controlled by Admin > Configuration > Maximum Values > Allowed Filename Extensions for uploading except a mismatch now prevents the product being added to cart
        **/
        
            
    if (isset($_GET['number_of_uploads']) and $_GET['number_of_uploads'] > 0) {
                            
                if (!
    zen_not_null($extensions)) { // Fill the $extensions array with the allowed filename extensions
                    
    if (!defined(UPLOAD_FILENAME_EXTENSIONS)) define ('UPLOAD_FILENAME_EXTENSIONS','jpg,jpeg,gif,png,eps,cdr,ai,pdf,tif,tiff,bmp,zip');
                    
    $extensions=explode(" ",preg_replace('/[.,;\s]+/',' ',UPLOAD_FILENAME_EXTENSIONS));
                }
                                
                if (empty(
    $_FILES['id']['tmp_name'])) { // If post_max_size is exceeded (the file is WAY too large) then the $_FILES array is empty, throw error
                    
    $the_list .= '<span class="alertBlack"> File is too large to upload, please select a smaller file.</span ';
                }
                
                foreach (
    $_FILES['id']['error'] as $error) {
                    if (
    $error == UPLOAD_ERR_NO_FILE) { // If no upload was selected throw error
                        
    $the_list .= '<span class="alertBlack"> Please select a file to upload. </span>';  
                    }                
                    if (
    $error == UPLOAD_ERR_INI_SIZE or $error == UPLOAD_ERR_FORM_SIZE) { // If upload_max_filesize is exceeded throw error
                        
    $the_list .= '<span class="alertBlack"> File is too large to upload, please select a smaller file.<span class="alertBlack">';
                    }
                    if (
    $error == UPLOAD_ERR_PARTIAL) { // If the upload was interrupted throw error
                        
    $the_list .= '<span class="alertBlack"> Sorry the upload was interrupted, please try again. <span class="alertBlack">';
                    } 
                    if (
    $error == '') {
                        foreach (
    $_FILES['id']['name'] as $filename) { //If no other errors check the file extension against the $extensions array and throw error if there is no match
                            
    $error_free 0;
                            
    $pathinfo pathinfo($filename);
                            
    $pathinfo $pathinfo[extension];
                            for(
    $i 0$i count($extensions); $i++) {
                                if (
    $extensions[$i] == "$pathinfo") {
                                
    $error_free 1;
                                break;
                                }
                            }
                            if (
    $error_free != 1) {
                                
    $the_list .= '<span class="altertBlack">' ERROR_FILETYPE_NOT_ALLOWED '<br/> Allowed extensions: ' UPLOAD_FILENAME_EXTENSIONS '</span>';                    
                            }
                        }
                        
                    }
                }
            }
        
    //EOF - FORCE FILE UPLOAD (Addition)
          
          
    if (isset($_POST['id'])) {
            foreach (
    $_POST['id'] as $key => $value) {
              
    $check zen_get_attributes_valid($_POST['products_id'], $key$value);
              if (
    $check == false) {
                
    $the_list .= TEXT_ERROR_OPTION_FOR '<span class="alertBlack">' zen_options_name($key) . '</span>' TEXT_INVALID_SELECTION '<span class="alertBlack">' . (zen_values_name($value) == 'TEXT' TEXT_INVALID_USER_INPUT zen_values_name($value)) . '</span>' '<br />';
              }
            }
          } 
    4) -- ONLY IF YOU HAVE NOT FOLLOWED POST #9 --

    Access the php.ini file on your server (or use a .htaccess override) and find:

    upload_max_filesize = ...
    post_max_size = ...

    upload_max_filesize should be set to the maximum file size that you would like to allow users to upload. This now controls the maximum upload file size (NOT THE ZEN CART ADMIN)

    post_max_size should be set to a value LARGER (by say +1M) than upload_max_filesize.

    5) -- ONLY IF YOU HAVE NOT FOLLOWED POST #9 --

    Navigate to Admin > Configuration > Maximum Values > Maximum File Upload Size

    Ensure that Maximum File Upload Size is LARGER (in bytes) than upload_max_filesize.

    Eg... if upload_max_filesize = 1M set Maximum File Upload Size to 1,048,577 or larger.

    6) To change the error messages you give your customer search the above code for the current error message and change it to a more appropriate one. If you had already followed post #9 and then changed the error messages you will now have to change the error messages again

  3. #13
    Join Date
    Jan 2011
    Posts
    6
    Plugin Contributions
    0

    Default Re: File upload module

    OMG, I have no idea if you're gonna see my post, but you are amazing! I can't thank you enough for this piece of code! Congrats and thank you, thank you, thank you! Works like a charm.

  4. #14
    Join Date
    Sep 2008
    Posts
    19
    Plugin Contributions
    2

    Default Re: File upload module

    NEW - Required file upload module:
    http://www.zen-cart.com/index.php?ma...oducts_id=1685

    Support forum:
    http://www.zen-cart.com/forum/showthread.php?t=159610

    Please use this module if you need to require file uploads

  5. #15
    Join Date
    Jan 2011
    Posts
    6
    Plugin Contributions
    0

    Default Re: File upload module

    Well, from what I could see, the fix you had in post #9 was working ok. But since you went through the trouble of writing a module, I wanted to give it a try, and I am here to spread the word: it works! I didn't have much time for testing, but it all seems to be fine. Once more, thanks for a great fix (desperately needed)!

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Thumbnail Preview of file after upload via Attribute File uploader?
    By NWFAP in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 7 Aug 2015, 03:40 AM
  2. Replies: 8
    Last Post: 22 May 2010, 04:47 PM
  3. NEW File Upload Module
    By kminnich in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 29 Jul 2008, 03:11 AM
  4. Upload Image or Upload File form
    By matthelm in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 30 Dec 2006, 01:13 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR