Thursday, September 2, 2010

How to get the distance between to location using the google map?

When we calculate the distance between two lat & long the distance would the air to air so distance is wrong,so you have to send both  lat & long to google to get the driving distance.
Given  below the code for it.
//intiat curl
$ch = curl_init();
//pass the  both start and end lat & long
//check google map doc for option
//mode=driving is for driving distance
//sensor=false for site ,for mobile then it is true
//reponse is json
curl_setopt($ch, CURLOPT_URL,
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $contents = curl_exec ($ch);

Working with php & ffmpeg

This the code for convert video using the ffmpeg.The php use the ffmpeg insstall in Linux system.
for the option please out the web site of ffmpeg

$uploadfile = "t1.3gp";
$uploadfile_flv = "video.flv";

//shell_exec('ffmpeg -i  '.$uploadfile.' -acodec libmp3lame -map_meta_data '.$uploadfile_flv.':'.$uploadfile.' -ar 22050 -ab 64000 -deinterlace -nr 500 -s 320x240 -aspect 4:3 -r 20 -g 500 -me_range 20 -b 200k -f flv -y '.$uploadfile_flv);

shell_exec('ffmpeg -i  '.$uploadfile.' -ar 22050 -ab 64000 -deinterlace -nr 500 -s 320x240 -aspect 4:3 -r 20 -g 500 -me_range 20 -b 200k -f flv -y '.$uploadfile_flv);

echo ('ffmpeg -i  '.$uploadfile.' -ar 22050 -ab 64000 -deinterlace -nr 500 -s 320x240 -aspect 4:3 -r 20 -g 500 -me_range 20 -b 200k -f flv -y '.$uploadfile_flv);

//$flvMetaUpdateCmd = "flvtool2 -U ".$uploadfile_flv;

$uploaddir = "./";
$png_file_name = "preview";

shell_exec("ffmpeg -i ".$uploadfile." -vcodec png -ss 00:00:05 -vframes 1 -an -f rawvideo -s 320x240 -y ".$uploaddir.$png_file_name.".png");

echo "

File Converted...";


How to create the application.ini in zend

 The code explain every thing
//this for all error  reporting
// Define path to application directory
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),


/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_PATH . '/configs/application.ini'
//to store the object/array/var in system use the register
 require_once 'Zend/Registry.php';
//this for mysql connection
 require_once 'Zend/Db/Adapter/Pdo/Mysql.php';

 Zend_Registry::set('varname',"value of var");
//there are two way of setting the database connection
//first by setting the using the Zend_Db_Adapter_Pdo_Mysql
//second using the Zend_Db:factory
/*$params = array('host' =>'localhost',
                'username' =>'root',
'password'  =>'password',
'dbname' =>'zend'
 $db=new Zend_Db_Adapter_Pdo_Mysql($params);
//this for load the application varibles,first parametes is application ini path & second is
//blok in application ini
 $config=new Zend_Config_Ini(APPLICATION_PATH.'/configs/application.ini','general');
 $db= Zend_Db::factory($config->db->adapter,$config->db->params->toArray());


Saturday, June 5, 2010

How to convert base64 string into image with php?

 First of all create the base64 string
  function encode_img($img)
           $fd = fopen ($img, 'rb');
           $size=filesize ($img);
           $cont = fread ($fd, $size);
           fclose ($fd);
           $encimg = base64_encode($cont);
           return $encimg;
         $image_base64=encode_img('123.jpg'); // to encode the image
then convert back to image into some location
$img = imagecreatefromstring(base64_decode($image_base64));
    if($img != false)
    imagejpeg($img, 'user_images/image.jpg');

Have Dream Day

Mysql query return the count from multiple table with left join

This the MySQL query with table where home table has one to many relation with many table,
 Here is code that return the count from multiple table.

  select,h.home_name,count(n.home_id) as ncount,
count(e.home_id) as ecount,count(b.home_id) as bcount,
count(s.home_id) as scount
 from home as h left join news as n on (
left join events as e on (
left join billboard as b on (
left join store as s on( where 1

Have Dream Day

Tuesday, May 18, 2010

Inline edit using the jQuery/Php

 here code for you,that did not need the any plug-in
  Just copy pest the code and add class to element so the it can peek up
  class name "editable"
 and also give id to the each div or span like "Aesop"
 so that u can fetch the id of the element

function($) {

    $.fn.inlineEdit = function(options) {
               options = $.extend({
            hover: 'hover',
            value: '',
            save: '',
            buttonText: 'Save',
            placeholder: 'Click to edit'
        }, options);

        return $.each(this, function() {
            $.inlineEdit(this, options);

    $.inlineEdit = function(obj, options) {
           var self = $(obj),
            placeholderHtml = ''+ options.placeholder +'';
        self.value = function(newValue) {
            if (arguments.length) {
      'value', $(newValue).hasClass('inlineEdit-placeholder') ? '' : newValue);
       self.value($.trim(self.text()) || options.value);

        self.bind('click', function(event) {
            var $this = $(;
            if ($'button')) {
                 var hash = {
                        value: $input = $this.siblings('input').val(),

                       //add more values here
                        id :$this.siblings('input').attr('id')
              if (($.isFunction( &&, event, hash)) !== false || ! {

                   //self is the element which is click
                   //if you want add other var then add here
           = ;
            } else if ($[0].tagName) || $this.hasClass('inlineEdit-placeholder')) {
                    .html(' ')
                        .bind('blur', function() {
                            if (self.timer) {
                            self.timer = window.setTimeout(function() {
                                self.html(self.value() || placeholderHtml);
                            }, 200);

        if (!self.value()) {
        } else if (options.value) {


                buttonText : 'Save',
               save: function(e,data) {
                var parent_id = jQuery('#cat').val();
                 //return confirm('You are about to change your name to "'+ data.value +'"\n\nAre you sure?'); 

                //this is ajax call
                       type: "GET",
                       url: '''&name='+data.value+'&parent_id='+parent_id,
                       success: function(res)
                       if(res == 0)
                          alert('Category name already exists,please use another name');
                          jQuery('#''Edit Category');
                   });//ajax end
                }//save callback function end
            });//inline edit function end
        });//jquery function end

Have Dream Day

Monday, April 26, 2010

how to clean the url in php?

 This is the code for remove the unwanted charecter from the uploaded file

 $_FILES['image']['name'] = strtolower(trim($_FILES['image']['name']));
                 $_FILES['image']['name'] = str_replace(array('\'',' ','\#','\$','\&','\!','\@','\#','\$','\%','\^','\&','\*','\(','\)','\_',
              '\+','\{','\}'),'', $_FILES['image']['name']);

have dream day