Monday, 16 February 2015

set timezone and get timezone in php

 1.) Set timezone :-
<?php echo date_default_timezone_set("Asia/Kolkata"); ?>

 2.) Get timezone :-
<?php echo date_default_timezone_get(); ?>

export sql table to csv format in php

<?php 
//First create db connection.
$output = "";
$sql = mysql_query("select col1,col2,col3 from table_name where 1");
$columns_total = mysql_num_fields($sql);
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\r\n";
while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'",';
}
$output .="\n";
}
$filename = "Vendor-data-export.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);

echo $output;
?>

Saturday, 14 February 2015

Create custom home page layout in magento

1.)  First go to app/design/frontend/rwd/default/layout/page.xml and following  code after one_page colamn structure

<page_home translate="label">
        <label>All home Layout Pages</label>
        <reference name="root">
            <action method="setTemplate"><template>page/home.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
            <action method="setLayoutCode"><name>home</name></action>
        </reference>
    </page_home>

2.) second open app/code/core/Mage/Page/etc/config.xml file and set following code after one_page colamn

<home module="page" translate="label">
                    <label>Home page</label>
                    <template>page/home.phtml</template>
                    <layout_handle>page_home</layout_handle>
                    <is_default>1</is_default>
                </home>

3.) And last go to admin->cms->pages in content tab select your home page.

Tuesday, 20 January 2015

get image height and width in php

<?php list($width, $height) = getimagesize('path_to_image');
echo $width."<br/>";
echo $height; 
?>
 
 
 
Powered by Crawlers group

how to count array value in jquery

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
function chksame(cl) {
var newArray = new Array();

var classnm = $(cl).attr("class");
 
var array = $("input[class^= '" + classnm + "']"); //get value by class name

$.each(array, function(key, value) {
card_value = array.eq(key).val();
   newArray.push(card_value);//push value in array.
  
});

counts = {};
jQuery.each(newArray, function(key,value) {
  if (!counts.hasOwnProperty(value)) {
    counts[value] = 1; //set count value
  } else {
    counts[value]++;
  }
 
  if(counts[value]>1 && value!="") //check if value greater than then alert massege.
  {
  alert("This order already exist");
  $(cl).val("");
  }
});
return false;
}
</script>

Powered by Crawlers group

Thursday, 8 January 2015

download file in php

function Download($path, $speed = null)
{
if (is_file($path) === true)
    {
set_time_limit(0);
while (ob_get_level() > 0)
        {
            ob_end_clean();
        }
$size = sprintf('%u', filesize($path));
        $speed = (is_null($speed) === true) ? $size : intval($speed) * 1024;
        header('Expires: 0');
        header('Pragma: public');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Type: application/octet-stream');
        header('Content-Length: ' . $size);
        header('Content-Disposition: attachment; filename="' . basename($path) . '"');
        header('Content-Transfer-Encoding: binary');

        for ($i = 0; $i <= $size; $i = $i + $speed)
        {
            echo file_get_contents($path, false, null, $i, $speed);

            while (ob_get_level() > 0)
            {
                ob_end_clean();
            }

            flush();
            sleep(1);
        }

        exit();
    }

    return false;
}
echo Download($file_path,500);

Saturday, 6 December 2014

Dynamicaly change page title in php

<?php ob_start(); //top of the page.
?>
<title>%TITLE%</title>

<?php 
echo page_title("page title");

function page_title($title) {  //dinamicaly set page title

$buffer=ob_get_contents();
ob_clean();
$buffer=str_replace("%TITLE%",$title,$buffer);
return $buffer;

}
?>