albundy11 1 Posted March 26, 2010 Posted March 26, 2010 Hi All !I would like to propose my customers to upload their own ZIP files from the product customization fields in front office.Pieces of solutions occurs in both french and english forums.Is there someone who could explain step by step how to proceed for that ?It would be appreciable to solve definitively this point : It would be nice to put [sOLVE] to this post.Thanks a lot ! Share this post Link to post Share on other sites
Pshopic 17 Posted March 26, 2010 Posted March 26, 2010 1. Go to your back office.2. Create a new product and then there will be "Customization" tab3. Enter number to "file fields".4. Then click to "update settings"5. After that you will see blank, there you can write upload detail.6. Then click to "save" button.7. Finally, go to your front office, click to product, there will see "Product customization" tab.I hope it will be helpfull to you. Share this post Link to post Share on other sites
albundy11 1 Posted March 29, 2010 Posted March 29, 2010 Hi Prestashopic,Thanks a lot for your support.The way you explained permits to upload picture formats files (png, jpeg, gif).I'm looking for uploading ZIP files.Best regards. Share this post Link to post Share on other sites
albundy11 1 Posted March 29, 2010 Posted March 29, 2010 Hi again,Someone told me : Help yourself and heaven will help you ! So, here is the solution :1/ Modify product.php as below : function isZIP($file) { /* Detect mime content type */ $mime_type = false; $types = array('multipart/x-zip','application/zip','application/x-zip-compressed','application/x-zip'); 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']; if (($pos = strpos($mime_type, ';')) !== false) $mime_type = substr($mime_type, 0, $pos); // is it a picture ? return $mime_type && in_array($mime_type, $types); } 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')))) && (!isZIP($file))) { $errors[] = $error; return false; } if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($file['tmp_name'], $tmpName)) { return false; } if (isZIP($file)) { $fileName = "P" . $fileName; if (!copy($tmpName, _PS_PROD_PIC_DIR_.$fileName)) { $errors[] = Tools::displayError('An error occurred during the file upload.'); return false; } $oldfile = './img/zip.jpg'; } else { $fileName = "J" . $fileName; if (!imageResize($tmpName, _PS_PROD_PIC_DIR_.$fileName)) { $errors[] = Tools::displayError('An error occurred during the image upload.'); return false; } $oldfile = $tmpName; } if (!imageResize($oldfile, _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.'); return false; } if (!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.'); return false; } $cart->addPictureToProduct(intval($product->id), $indexes[$fieldName], $fileName); unlink($tmpName); } return true; } 2/ Modify displayImage.php as follow : <?php $name = $_GET['name']; $file = $_GET['img']; require_once(dirname(__FILE__).'/../config/config.inc.php'); require_once(dirname(__FILE__).'/init.php'); $type = substr($file, 0, 1); $img = substr($file, 1); if ($img AND Validate::isMd5($img) AND $name AND Validate::isGenericName($name) AND file_exists(_PS_PROD_PIC_DIR_.$file)) { if ($type == "P") { header('Content-type: application/zip'); /*'multipart/x-zip','application/zip','application/x-zip-compressed','application/x-zip'*/ $ext = ".zip"; } elseif ($type == "J") { header('Content-type: image/jpeg'); $ext = ".jpg"; } header('Content-Disposition: attachment; filename="'.$name.$ext.'"'); echo file_get_contents(_PS_PROD_PIC_DIR_.$file); } ?> 3/ Add ZIP icon (zip.jpg) into yourwebsite/imgBye. Share this post Link to post Share on other sites
mimiagi 0 Posted May 10, 2010 Posted May 10, 2010 It is not work !Why ? Share this post Link to post Share on other sites
dibs223 2 Posted June 9, 2010 Posted June 9, 2010 I dont have a Customization” tabhelppppppp plz why do i not have this! I cannot upload zip or rar files Share this post Link to post Share on other sites
mimiagi 0 Posted June 10, 2010 Posted June 10, 2010 And now, how to have a progression bar to inform user during a long time upload ? Share this post Link to post Share on other sites
rafael_store 0 Posted June 22, 2010 Posted June 22, 2010 The code is not working, what could be the problem ?However, when I try having changes to upload pdf and ai files, So it works. Share this post Link to post Share on other sites
rafael_store 0 Posted June 22, 2010 Posted June 22, 2010 He intentado tambien y no funciona; solo funciona con .pdf y .ai Share this post Link to post Share on other sites
TassaDarK 4 Posted September 20, 2010 Posted September 20, 2010 Hi! Any solution to zip file problem? Here is another one with the same problem.Thank you! Share this post Link to post Share on other sites
SonnyBoyII 5 Posted March 28, 2011 Posted March 28, 2011 any solution? please... Share this post Link to post Share on other sites
zarkon 2 Posted August 14, 2011 Posted August 14, 2011 anyone have zip upload working on 1.4.4? Share this post Link to post Share on other sites
logicallimit 7 Posted December 24, 2012 Posted December 24, 2012 The code is not working, what could be the problem ? However, when I try having changes to upload pdf and ai files, So it works. Can you please post the code the worked for you to upload pdf and other files ? 1 Share this post Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now