Tag Archives: PHP

PHP script to download the PDF file

<?php
 $file = 'testFile.pdf'; // file to be downloaded
 header("Expires: 0");
 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
 header("Cache-Control: no-store, no-cache, must-revalidate");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");  header("Content-type: application/pdf");
 header('Content-length: '.filesize($file));
 header('Content-disposition: attachment; filename='.basename($file));
 readfile($file);
 exit;
?>

Create and download excel file – PHP

<?php
 $file = 'excelFile-'.date("Y-M-D")."-".time().'.xls';
 ob_start();
 echo '<table border="1"> ';
 echo '<tr><th>Product Name </th><th>Category</th><th>Active</th></tr>';
 for ($i=0; $i<=10; $i++) {
  echo "<tr><td>Product$i</td><td align='center'>Category $i</td><td>Active</td></tr>";
 }
 echo '</table>';
 $content = ob_get_contents();
 ob_end_clean();
 header("Expires: 0");
 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
 header("Cache-Control: no-store, no-cache, must-revalidate");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");  header("Content-type: application/vnd.ms-excel;charset:UTF-8");
 header('Content-length: '.strlen($content));
 header('Content-disposition: attachment; filename='.basename($file));
 echo $content;
 exit;
?>

Image resize script – PHP

<?php
 class SimpleImage {
 function resizeImage($max_width,$max_height,$url,$destination){
  $quality = 95; $source_pic = ''.$url.'';
  $src = imagecreatefromjpeg($source_pic);
  list($width,$height)=getimagesize($source_pic);
  $x_ratio = $max_width / $width; $y_ratio = $max_height / $height;
  if( ($width <= $max_width) && ($height <= $max_height) ){
   $tn_width = $width; $tn_height = $height; }
  elseif (($x_ratio * $height) < $max_height){
   $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; }
  else {
   $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } $tmp=imagecreatetruecolor($tn_width,$tn_height);
  imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
  imagejpeg($tmp,$destination,$quality); imagedestroy($tmp);
 }
}
 $image = (object) new resizeImage();
 $image->resizeImage(100,80,$source,$destination);
?>

Use a Coupon Code for Specific Products – Magento

In our Magento ACP, simply click on Shopping Cart Price Rules (Which is under the top menu “Promotions”) – and then click Add New Rule.
On the left you can see three tabs, in the uppermost one you’ll have to name your Price Rule, choose which website it will be activated on and what customers will see it, and also name the actual coupon code itself.

Then click on the next tab entitled “conditions” which is the important one, as this area specifies which products/categories will be available for the promotion. So, click the little green plus, and then select “Product Attribute Combination” .

After that again click on the next green button and select the option “SKU”(A unique name given to each products) from the dropdown .
Then modify the value of “IS” to “IS ONE OF” and the click on the small rectangular box (which is white in color ) .

You can all the products added . please sleect the products for which you want to add promotion .

Further click on the next tab “Action” where you have to mentoned discount amounnt and all .

Save all these details and inform the users about this promotion by sending newsletter