mbrown.c3d Posted August 27, 2009 Share Posted August 27, 2009 Hello everyone,When adding a file upload option to a product's customization options it states that jpg, gif, and png are the available extensions. Is it possible to add a .zip extension to PrestaShop?With a zip extension comes a larger size than what PrestaShop can currently handle. How can you modify the maximum file size to be uploaded? I have read other threads about modifying an htaccess file, but I was unable to find this.Thank you!Matt Link to comment Share on other sites More sharing options...
CYTechnologies Posted August 27, 2009 Share Posted August 27, 2009 Yes this is definitely possible, however, it will require a bit of modification though - are you comfortable with editing php code? :-) Link to comment Share on other sites More sharing options...
mbrown.c3d Posted August 27, 2009 Author Share Posted August 27, 2009 Yep! Just tell me what files to dig into.Thanks!Matt Link to comment Share on other sites More sharing options...
CYTechnologies Posted August 27, 2009 Share Posted August 27, 2009 Have to do a little research into which exact function, but will lay it out in a step format for you when I get it done (probably tomorrow, its late here :-) ) Link to comment Share on other sites More sharing options...
mbrown.c3d Posted August 27, 2009 Author Share Posted August 27, 2009 Thank you! I really appreciate the help! I will keep an eye out for your post.Matt Link to comment Share on other sites More sharing options...
mbrown.c3d Posted August 29, 2009 Author Share Posted August 29, 2009 Did you have a chance to look at this?Thanks,Matt Link to comment Share on other sites More sharing options...
CYTechnologies Posted August 29, 2009 Share Posted August 29, 2009 Hello Matt,Sorry I've been very busy these past few days :-)Okay heres what I've found so far...#1. For obvious reasons change the text found on products.tpl (located in your active theme) around line 413 in regards to GIF, JPG and add ZIP.#2. Open /yourstore/products.php and search for the function "pictureUpload" - its around line 13-14.#3. Update this function to handle other uploads besides Images.#4. This should take the user through the cart process fine, however there will need to be some updating in the back end when you are viewing the order so you can download he zip file instead of looking at a red x.This is as far as I've gotten so far, sorry once again. Link to comment Share on other sites More sharing options...
mbrown.c3d Posted August 31, 2009 Author Share Posted August 31, 2009 Hi CY,Thanks for the help so far, but I don't think I am that well versed in adding zip file types to the php. I have found the section, but it doesn't even list the current file types: jpg, gif, png.function pictureUpload(Product $product, Cart $cart){ global $errors; if (!$fieldIds = $product->getCustomizationFieldIds()) return false; $authorizedFileFields = array(); foreach ($fieldIds AS $fieldId) if ($fieldId['type'] == _CUSTOMIZE_FILE_) $authorizedFileFields[intval($fieldId['id_customization_field'])] = 'file'.intval($fieldId['id_customization_field']); $indexes = array_flip($authorizedFileFields); foreach ($_FILES AS $fieldName => $file) if (in_array($fieldName, $authorizedFileFields) AND isset($file['tmp_name']) AND !empty($file['tmp_name'])) { $fileName = md5(uniqid(rand(), true)); if ($error = checkImage($file, intval(Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE')))) $errors[] = $error; if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($file['tmp_name'], $tmpName)) return false; /* Original file */ elseif (!imageResize($tmpName, _PS_PROD_PIC_DIR_.$fileName)) $errors[] = Tools::displayError('An error occurred during the image upload.'); /* A smaller one */ elseif (!imageResize($tmpName, _PS_PROD_PIC_DIR_.$fileName.'_small', intval(Configuration::get('PS_PRODUCT_PICTURE_WIDTH')), intval(Configuration::get('PS_PRODUCT_PICTURE_HEIGHT')))) $errors[] = Tools::displayError('An error occurred during the image upload.'); elseif (!chmod(_PS_PROD_PIC_DIR_.$fileName, 0777) OR !chmod(_PS_PROD_PIC_DIR_.$fileName.'_small', 0777)) $errors[] = Tools::displayError('An error occurred during the image upload.'); else $cart->addPictureToProduct(intval($product->id), $indexes[$fieldName], $fileName); unlink($tmpName); } return true;}On a side note, I have updated my php.ini file to handle larger upload sizes which is a start. Thanks!Matt Link to comment Share on other sites More sharing options...
mbrown.c3d Posted September 1, 2009 Author Share Posted September 1, 2009 *BumpI really need this today if at all possible.Thanks!Matt Link to comment Share on other sites More sharing options...
CYTechnologies Posted September 1, 2009 Share Posted September 1, 2009 Hey Matt,Sorry mate, I've just been slammed with work. I probably can't get this to you today, maybe tomorrow morning. Link to comment Share on other sites More sharing options...
mbrown.c3d Posted September 8, 2009 Author Share Posted September 8, 2009 Hi CY,Did you ever have a chance to look at this? Based on the view count on this post, I would imagine that many others are looking for a solution for this as well.Thanks!Matt Link to comment Share on other sites More sharing options...
stevel Posted September 8, 2009 Share Posted September 8, 2009 I was also working on this issue.I believe the function you want to modify is the CheckImage()This function is in the images.inc.php around line 10-46here you will find your extensions. function checkImage($file, $maxFileSize) { if ($file['size'] > $maxFileSize) return Tools::displayError('image is too large').' ('.($file['size'] / 1000).Tools::displayError('KB').'). '.Tools::displayError('Maximum allowed:').' '.($maxFileSize / 1000).Tools::displayError('KB'); if (!isPicture($file)) return Tools::displayError('image format not recognized, allowed formats are: .gif, .jpg, .png'); if ($file['error']) return Tools::displayError('error while uploading image; change your server\'s settings'); return false; } the second condition checks to see the file typeThis function looks at the extension function isPicture($file) { /* Detect mime content type */ $mime_type = false; $types = array('image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'); if (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME); $mime_type = finfo_file($finfo, $file['tmp_name']); finfo_close($finfo); } elseif (function_exists('mime_content_type')) $mime_type = mime_content_type($file['tmp_name']); elseif (function_exists('exec')) $mime_type = trim(exec('file -b --mime-type '.escapeshellarg($file['tmp_name']))); if (empty($mime_type)|| $mime_type == 'regular file') $mime_type = $file['type']; // is it a picture ? return $mime_type && in_array($mime_type, $types); } You should be able to add onto the array list $types = array('image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'file/zip'); You'll have to make other changes here and there, I'll post them when I get there.My code might differ from yours, I had previously modified. Link to comment Share on other sites More sharing options...
mbrown.c3d Posted September 8, 2009 Author Share Posted September 8, 2009 Thanks for pointing me to this file! So I got the zip extension to finally be read, but there is still a '1. An error occurred during the image upload.' returned, and this language doesn't appear to be coming from the same file. Thoughts? My form processing code gave me this: POST:Array ( [textField26] => [quantityBackup] => [submitCustomizedDatas] => 1 ) FILES:Array ( [file25] => Array ( [name] => testzip.zip [type] => application/x-zip [tmp_name] => C:\Windows\Temp\phpA561.tmp [error] => 0 [size] => 40128 ) ) To get the zip extension to be read, I modified my php.ini file to allow for large file uploads and large posts, and added these MIME types to line 76 in the array: 'application/zip', 'application/x-zip-compressed', 'application/x-zip'I also found that $maxFileSize returns a smaller size than what I have defined in my php.ini file. Where is this variable defined?I am going to keep messing with this, and will post a solution if I find one. Link to comment Share on other sites More sharing options...
mbrown.c3d Posted September 8, 2009 Author Share Posted September 8, 2009 I can't look at this until later, but I think the problem I am having is with PS trying to create a thumbnail of the ZIP with imageResize() which causes the upload to fail. I need to write a conditional that will allow for this function to be ignored when it is a ZIP extension.Let me know if you solve this before I do. Link to comment Share on other sites More sharing options...
CYTechnologies Posted September 9, 2009 Share Posted September 9, 2009 Hey matt, you have the right idea, as soon as the file gets uploaded and PS tries to send it to the image function you need to stop it, still save the image within the custom fields table so you can pull it later though. Link to comment Share on other sites More sharing options...
mbrown.c3d Posted September 9, 2009 Author Share Posted September 9, 2009 I think I need a little help with this piece of it... any thoughts? Link to comment Share on other sites More sharing options...
kamaltin Posted September 10, 2009 Share Posted September 10, 2009 this is code from product.php/function pictureUpload(Product $product, Cart $cart) if ($error = checkImage($file, intval(Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE')))) Configuration - is table in PS Database. PS_PRODUCT_PICTURE_MAX_SIZE is setted in the tab BO/Preferences/Product. Mine is 12000000 byte.we are working about same problem. see other topics:http://www.prestashop.com/forums/viewthread/27502/http://www.prestashop.com/forums/viewthread/27570/a suggest keep one topic only. Link to comment Share on other sites More sharing options...
stevel Posted September 10, 2009 Share Posted September 10, 2009 Thank you very much. I'll be sure to change that value. Link to comment Share on other sites More sharing options...
albundy11 Posted March 26, 2010 Share Posted March 26, 2010 Hi mbrown.c3d,Can you help PS community by telling how you solved this problem ?It would be appreciable.Thanks. Link to comment Share on other sites More sharing options...
TassaDarK Posted September 3, 2010 Share Posted September 3, 2010 It would be VERY appreciable... Link to comment Share on other sites More sharing options...
kamaltin Posted March 4, 2011 Share Posted March 4, 2011 Hi,I found someone already solved "zip" problem and even more. Look at this link: http://www.printdesigns.com/content/9-faq/I sent message to site webmaster. I hope he will reply. Link to comment Share on other sites More sharing options...
padratoos Posted July 26, 2013 Share Posted July 26, 2013 Is there a way to add zip format? Link to comment Share on other sites More sharing options...
Carlo Delgado Posted September 28, 2017 Share Posted September 28, 2017 Hello, anyone solved this issue? I feel like zip and pdf file load but in the end I gave an error about the format files restricting png, gif and jpg. Please I need help, I did all I found on this forum... Thanks, Link to comment Share on other sites More sharing options...
Recommended Posts