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,
"http://maps.google.com/maps/api/directions/json?origin=".trim($latitude).",".trim($longitude)."&destination=".$obj->latitude.",".$obj->longitude."&mode=driving&alternatives=false&units=imperial&sensor=false");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $contents = curl_exec ($ch);
$contents=json_decode($contents);
$distance=$contents->routes[0]->legs[0]->distance->text

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
error_reporting(E_ALL|E_STRICT);
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || 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'),
    get_include_path(),
)));

//database


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

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    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);
 $db->setFetchMode(Zend_Db::FETCH_OBJ);*/
//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());
 Zend_Registry::set('db',$db);

$application->bootstrap()
            ->run();

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.id,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 (h.id=n.home_club_id)
left join events as e on (h.id=e.home_id)
left join billboard as b on (h.id=b.home_id)
left join store as s on(h.id=s.home_id) where 1

Have Dream Day

Tuesday, May 18, 2010

Inline edit using the jQuery/Php

Hi,
 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) {
                self.data('value', $(newValue).hasClass('inlineEdit-placeholder') ? '' : newValue);
            }
            return self.data('value');
        }
       self.value($.trim(self.text()) || options.value);

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

                       //add more values here
                        id :$this.siblings('input').attr('id')
                          };
                
              if (($.isFunction(options.save) && options.save.call(self, event, hash)) !== false || !options.save) {
                    self.value(hash.value);

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

        if (!self.value()) {
            self.html($(placeholderHtml));
        } else if (options.value) {
            self.html(options.value);
        }
    }

})(jQuery);







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

                //this is ajax call
                    jQuery.ajax({
                       type: "GET",
                       url: ''+data.id+'&name='+data.value+'&parent_id='+parent_id,
                       success: function(res)
                     {
                       
                       if(res == 0)
                        {
                          alert('Category name already exists,please use another name');
                          jQuery('#'+data.id).html('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?

Hi
 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