php - Download product images in a zip on click of download button in magento -
i have custom page specific products of category.
here link , code showing images only.
<div style="float:left; width:100%;"> <?php $_helper = $this->helper('catalog/output'); ?> <?php $product = $this->getproduct(); ?> <?php foreach ($product->getmediagalleryimages() $image) :?> <div style="width: 48%; margin:1%;float:left"> <img width="100%;" src="<?php echo mage::helper('catalog/image')->init($product, 'image', $image->getfile()); ?>" alt="<?php echo $product->getname()?>" /> </div> <?php endforeach; ?> </div> <div style="float:left; width:100%;"> <button type="button" style="display:block;margin:0 auto;">download</button> </div>
now need download images of product on click of button, link http://thevastrafashion.com/english/testing-1.html how can achieve this. if want more please leave comment.
you can following achieve this.
foreach ($sku $key => $value) { $productid = $value; $products = mage::getmodel('catalog/product')->loadbyattribute('sku', $productid); $instock = mage::getmodel('cataloginventory/stock_item')->loadbyproduct($products)->getisinstock(); if($instock) { array_push($file_arr, (string) mage::helper('catalog/image')->init($products, 'image')); } } if(count($file_arr)>0) { $result = create_zip($file_arr); } function create_zip($files = array()) { try{ $zip = new ziparchive(); $tmp_file = tempnam('.', ''); $zip->open($tmp_file, ziparchive::create); foreach ($files $file) { $download_file = file_get_contents($file); $zip->addfromstring(basename($file), $download_file); } $zip->close(); header('content-disposition: attachment; filename=download.zip'); header('content-type: application/zip'); header("accept-ranges: bytes"); header("pragma: public"); header("expires: -1"); header("cache-control: public, must-revalidate, post-check=0, pre-check=0"); header('content-length: ' . filesize($tmp_file)); $chunksize = 8 * (1024 * 1024); //8mb (highest possible fread length) $handle = fopen($tmp_file, 'rb'); $buffer = ''; while (!feof($handle) && (connection_status() === connection_normal)) { $buffer = fread($handle, $chunksize); print $buffer; ob_flush(); flush(); } if(connection_status() !== connection_normal) { echo "connection aborted"; } fclose($handle); } catch(exception $e) { mage::log($e,null,'download_error.log'); } }
this reference code only. need change according requirement.
Comments
Post a Comment