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

Friday, April 23, 2010

Zend Framework Tutorials

1.first set the bootstrap

 protected function _initAppAutoload()
    {
        $moduleLoad = new Zend_Application_Module_Autoloader(array(
           'namespace' => '',
           'basePath'   => APPLICATION_PATH
        ));
    }


2.set up the database connection in another class file or config.ini
  first write code in ini file
   [general]
 db.adapter = PDO_MYSQL
 db.config.host = localhost
 db.config.user = root
 db.config.password = password
 db.config.dbname = zend


  then in public index.php write code
  
$config =new Zend_Config_Ini(APPLICATION_PATH.'/configs/application.ini','general');
Zend_Registry::set('config',$config);
//database
$db = Zend_Db::factory($config->db->adapter,$config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);


3.create the class in model and give the name of the table

Zend Framework,bootstrap file autoload

Hi,
 If you want to access the any model or other class then in application folder,the you must auto load the class in bootstrap file,and write the code below

  protected function _initAppAutoload()
    {
        $moduleLoad = new Zend_Application_Module_Autoloader(array(
           'namespace' => '',
           'basePath'   => APPLICATION_PATH
        ));
    }


Have Dream Day

Monday, March 22, 2010

XMLRPC class

Hi,
 This the class for xmlrpc,  download
for more details click here 
test file

include_once "classfile.php";
 //echo "wp.getUsersBlogs";
 $client = new IXR_Client('http://localhost');
  echo "method name"."
";
 if(!$client->query('method name','param1','param1'))
 {
  die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());

 }

Saturday, March 20, 2010

Wordpress plug-in that upload image with post

Hi
I am here to give source code for plug-in that upload image with each post and store the data in post meta.

<?php 
/*
Plugin Name: artical
Version: 1.0
Plugin URI: http://rubyid10.blogspot.com    
Author: Sameer
Author URI: http://rubyid10.blogspot.com
Description: Tool to add custom files to post  
  */
        define('ARTICAL_FOLDER', dirname(plugin_basename(__FILE__)));
        define(DIRECTORY_SEPARATOR,'/');
        define('ARTICAL_IMG_WEBSITE_FULLPATH',WP_CONTENT_DIR."/uploads/artical/website/");
        define('ARTICAL_IMG_WEBSITE_URL', get_option('siteurl').'/wp-content/uploads/artical/website/');
        
        define('ARTICAL_IMG_IPHONE_FULLPATH',WP_CONTENT_DIR."/uploads/artical/iphone/");
        define('ARTICAL_IMG_IPHONE_URL', get_option('siteurl').'/wp-content/uploads/artical/iphone/');
        define('THUMB_WIDTH',60);
        define('THUMB_HEIGHT',60);

        define('ARTICAL_IMG_INTER_FULLPATH',WP_CONTENT_DIR."/uploads/artical/inter/");
        define('ARTICAL_IMG_INTER_URL', get_option('siteurl').'/wp-content/uploads/artical/inter/');
        define('INTER_WIDTH',150);
        define('INTER_HEIGHT',150);
        ////////////////////////////////
        
        
        define('GALLERY_IMG_WEBSITE_FULLPATH',WP_CONTENT_DIR."/uploads/gallery/website/");
        define('GALLERY_IMG_WEBSITE_URL', get_option('siteurl').'/wp-content/uploads/gallery/website/');
        
        define('GALLERY_IMG_IPHONE_FULLPATH',WP_CONTENT_DIR."/uploads/gallery/iphone/");
        define('GALLERY_IMG_IPHONE_URL', get_option('siteurl').'/wp-content/uploads/gallery/iphone/');
        define('GALLERY_THUMB_WIDTH',60);
        define('GALLERY_THUMB_HEIGHT',60);

        define('GALLERY_IMG_INTER_FULLPATH',WP_CONTENT_DIR."/uploads/gallery/inter/");
        define('GALLERY_IMG_INTER_URL', get_option('siteurl').'/wp-content/uploads/gallery/inter/');
        define('GALLERY_INTER_WIDTH',150);
        define('GALLERY_INTER_HEIGHT',150);
        //////////////////////////////////////////////////////////
        
        
        define('BLOG_IMG_WEBSITE_FULLPATH',WP_CONTENT_DIR."/uploads/blog/website/");
        define('BLOG_IMG_WEBSITE_URL', get_option('siteurl').'/wp-content/uploads/blog/website/');
        
        define('BLOG_IMG_IPHONE_FULLPATH',WP_CONTENT_DIR."/uploads/blog/iphone/");
        define('BLOG_IMG_IPHONE_URL', get_option('siteurl').'/wp-content/uploads/blog/iphone/');
        define('BLOG_THUMB_WIDTH',60);
        define('BLOG_THUMB_HEIGHT',60);

        define('BLOG_IMG_INTER_FULLPATH',WP_CONTENT_DIR."/uploads/blog/inter/");
        define('BLOG_IMG_INTER_URL', get_option('siteurl').'/wp-content/uploads/blog/inter/');
        define('BLOG_INTER_WIDTH',150);
        define('BLOG_INTER_HEIGHT',150);
        
        
        
        
        
        
         define('UPLOAD_IMAGE_TYPE','gif,png,jpeg,jpg');
         //t
        add_action('admin_menu','change_form');
         /* Use the admin_menu action to define the custom boxes */
        //this will add artical_gallery_blog box
        add_action('admin_menu', 'add_artical_gallery_blog');
     
        
        /* Use the save_post action to do something with the data entered */
         add_action('save_post', 'artical_save_postdata');
         
         
         
    function change_form()
             {
              ob_start("modify_buffer");         
             }
             
         function modify_buffer( $buffer )
        {
        $buffer = str_replace( '<form name="post"', '<form name="post" enctype="multipart/form-data"',
         $buffer );
         return $buffer;
    }
         /* Adds a custom section to the "advanced" Post and Page edit screens */
///////////////////////////////////////////////////////////////////////////
    function add_artical_gallery_blog() 
{

  if( function_exists( 'add_meta_box' )) 
              {
              /////////////////add artical
            add_meta_box( 'artical_id', __( 'Image Upload', 'myplugin_textdomain' ), 
                        'artical_custom_box', 'post', 'advanced','high' );
            add_meta_box( 'artical_id', __( 'Image Upload', 'myplugin_textdomain' ), 
                        'artical_custom_box', 'page', 'advanced' );
            
           }
          
} 
     
///////////////////////////////////////////////////////////////////
/* Prints the inner fields for the custom post/page section */
//////////////////this for get the category image,used in xmlrpc response
 function get_category_image_names( $cat_id = false, $type = false )
    {
        $category_image_names = get_option( 'ciii_image_names' );
        if ( $cat_id !== false && $type ) {
            return $category_image_names[ $cat_id ][ $type ];
        }
        if ( $cat_id !== false ) {
            if ( ! isset( $category_image_names[ $cat_id ] ) ) return false;
            return $category_image_names[ $cat_id ];
        }
        return $category_image_names;
    }
////////////////////////////////////////////////////////////////////////////////////
    function artical_custom_box() 
{
                // Use nonce for verification
                    echo '<input type="hidden" name="myplugin_noncename" id="myplugin_noncename" value="' . 
                    wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
                    // The actual fields for data entry
                    
                   // $image_meta_data = get_post_meta($_GET['post'], '_artical',true);
                    if($_GET['action']=='edit'){
                    $keys = get_post_custom_keys(trim($_GET['post']));
                    if(in_array('_artical',$keys))
                    {
                    $type ="_artical";
                    }else if(in_array('_gallery',$keys))
                    {
                    $type ="_gallery";
                    }
                    else
                    {
                    $type ="_blog";
                    
                    }
                    }
                    
                    ?>
                    <strong>Note:</strong>
                    <br/>
                    <span>Choose "Article" to upload image for Article. </span>
                    <br/>
                    <span>Choose "Gallery" to upload image for Gallery. </span>
                    <br/>
                    <span>Choose "Blog" to upload image for Blog. </span>
                    <br/>
                    <?php 
                     if($_GET['action']=='edit')
                  {
                      $div_tag="<div align='center'>";
                      $image_meta_data = get_post_meta($_GET['post'],$type,true);  
                    
                      
                      
                      switch($type)
                      {
                      case '_artical':
                      $image_path = ARTICAL_IMG_INTER_URL;
                      break;
                      
                      case '_gallery':
                      $image_path = GALLERY_IMG_INTER_URL;
                      break;
                      case '_blog':
                      $image_path = BLOG_IMG_INTER_URL;
                      break;
                      }        
                      
                      $div_tag.="<img src='".$image_path.$image_meta_data."'>";
                      
                      $div_tag.= "</div>";
                      echo $div_tag;
                        
                      
                    }
                echo "
                <script>
                jQuery(document).ready(function($){
                 
                $('#artical_image').change(function(){
                    
                    $('#artical_image_edit').attr('value','1');
                
                });
              });
               </script>
                 ";
                 
                echo '<br/><div align=\'center\'><label for="Article Image">' . __("Upload Image for", 'myplugin_textdomain' ) . '</label> ';
                echo "<input type='hidden' id='artical_image_edit' name='artical_image_edit' value='0'>";
                ?>
                
                    <select name='image_type'>
                    <option value="_artical"<?php if($type == '_artical')echo "selected='yes'"?>>Article
                    </option>
                    <option value="_gallery"<?php if($type == '_gallery')echo "selected='yes'"?>>Gallery
                    </option>
                    <option value="_blog"<?php if($type == '_blog')echo "selected='yes'"?>>Blog
                    </option>
                    </select>
                 
                 
                <?php 
              echo '<input type="file" name="artical_image" id=\'artical_image\'/></div>';
              ?>
              <div align="center">
              <br/>
              <span>File upload limit 2MB. </span>
              <br/>
              <span>Supported file types: gif, png, jpg . </span>
              </div>
              <?php 
}

//////////////////////////////////////////////////////////////////////////////////
  
//////////////////////////////////////////////////////////////////////////////////            
                    
/* When the post is saved, saves our custom data */
    function artical_save_postdata( $post_id ) {

  // verify this came from the our screen and with proper authorization,
  // because save_post can be triggered at other times

          if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) )) {
                return $post_id;
          }

  // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want
  // to do anything
          if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
            return $post_id;

  
  // Check permissions
          if ( 'page' == $_POST['post_type'] ) {
            if ( !current_user_can( 'edit_page', $post_id ) )
              return $post_id;
          } else {
            if ( !current_user_can( 'edit_post', $post_id ) )
              return $post_id;
          }

  // OK, we're authenticated: we need to find and save the data

          $mydata = $_POST['myplugin_new_field'];
         if($_POST['artical_image_edit'] ==1)
          {
              $file_upload_error="";
            /*echo "<pre>";
              print_r($_FILES);
              exit;*/
              $_FILES['artical_image']['name'] = strtolower(trim($_FILES['artical_image']['name']));
          if(trim($_FILES['artical_image']['name']) == '')
          {       
           $file_upload_error=1;
            wp_redirect(get_option('siteurl').'/wp-content/themes/classic/error.php?cerror='.$file_upload_error);
             exit;
        }
            $image_extesion_array = explode(",",UPLOAD_IMAGE_TYPE);
            $image_path = pathinfo($_FILES['artical_image']['name']);
            $image_extension = $image_path['extension'];
        //image extesion test
           if(!in_array($image_extension,$image_extesion_array))
          {       
            $file_upload_error=2;
            wp_redirect(get_option('siteurl').'/wp-content/themes/classic/error.php?cerror='.$file_upload_error);
             exit;
        }
        if($file_size >= 2000)
          {       
               $file_upload_error=3;
            wp_redirect(get_option('siteurl').'/wp-content/themes/classic/error.php?cerror='.$file_upload_error);
             exit;
        }
        
  
           global $wpdb;
          
           
        if (!empty($_POST["ID"])){
                $id = $_POST["ID"];
            }
              
        if(trim($_FILES['artical_image']['name']) != '')
              {  
            
             $post_id=$_POST['post_ID'];
            $filename = trim($post_id.'_'.$_FILES['artical_image']['name']);
            $filename = strtolower($filename);
             $filename = str_replace(' ','_',$filename);
             $filename = str_replace("\'",'_',$filename);
             $filename = str_replace("\&",'_',$filename);
             $filename = str_replace("\$",'_',$filename);
             
             
            
            switch(trim($_REQUEST['image_type']))
            {
            case '_artical':
              $meta_key = '_artical';
              $meta_value  = $filename;
              $upload_path = ARTICAL_IMG_WEBSITE_FULLPATH;
              $thumbnail_path = ARTICAL_IMG_IPHONE_FULLPATH;
              $thumb_width = THUMB_WIDTH;
              $thumb_height = THUMB_HEIGHT;
              $inter_path = ARTICAL_IMG_INTER_FULLPATH;
              $inter_width = INTER_WIDTH;
              $inter_height = INTER_HEIGHT;
                break;
                
              case '_gallery':
              $meta_key = '_gallery';
              $meta_value  = $filename;
              $upload_path = GALLERY_IMG_WEBSITE_FULLPATH;
              $thumbnail_path = GALLERY_IMG_IPHONE_FULLPATH;
              $thumb_width = GALLERY_THUMB_WIDTH;
              $thumb_height = GALLERY_THUMB_HEIGHT;
              $inter_path = GALLERY_IMG_INTER_FULLPATH;
              $inter_width = GALLERY_INTER_WIDTH;
              $inter_height = GALLERY_INTER_HEIGHT;
              break;
              
              case '_blog':
              $meta_key = '_blog';
              $meta_value  = $filename;
              $upload_path = BLOG_IMG_WEBSITE_FULLPATH;
              $thumbnail_path = BLOG_IMG_IPHONE_FULLPATH;
              $thumb_width = BLOG_THUMB_WIDTH;
              $thumb_height = BLOG_THUMB_HEIGHT;
              $inter_path = BLOG_IMG_INTER_FULLPATH;
              $inter_width = BLOG_INTER_WIDTH;
              $inter_height = BLOG_INTER_HEIGHT;
              break;
            
            } 
            
            if($_REQUEST['action'] == 'editpost')
            {
              update_post_meta($post_id,$meta_key,$meta_value);
              //for delete the already exists file
                /*$image_meta_data = get_post_meta($post_id,$meta_key,true);
                      if( is_file($upload_path.$image_meta_data))
                        @unlink($upload_path.$image_meta_data);
                        @unlink($thumbnail_path.$image_meta_data);
                        @unlink($inter_path.$image_meta_data);*/
                        
                        
              
              
            }else 
            {
            add_post_meta($post_id, $meta_key, $meta_value);
            } 
              //file upload move
            move_uploaded_file($_FILES['artical_image']['tmp_name'],
            $upload_path.$filename);
             //for thumbnail image
            include_once('thumbnail_class.php');
            $image = new Resize_Image;
            $image->new_width = $thumb_width ;
            $image->new_height = $thumb_height;
            $image->image_to_resize = $upload_path.$filename; // Full Path to the file
            $image->ratio = true; // Keep Aspect Ratio?
            $image->save_folder = $thumbnail_path;
            $process = $image->resize();
            //fot intermediate image 
            $image1 = new Resize_Image;
            $image1->new_width = $inter_width;
            $image1->new_height = $inter_height;
            $image1->image_to_resize =$upload_path.$filename; // Full Path to the file
            $image1->ratio = true; // Keep Aspect Ratio?
            $image1->save_folder =$inter_path;
            $process = $image1->resize();
          }
          }//for file upload checking end
        ////////////////////////////////////////////////////////////////////
        /*echo "<pre>";
          print_r($_FILES);
          exit;*/
       
          
return $mydata;
}
?>

Friday, March 19, 2010

jquery ajax uploader with progres bar

I implement the jquery  ajax uploader, you find all the details better at here,
 I get many problem when I use it,

For implement in php
script type="text/javascript" src='js/jquery-1.4.min.js'>
</script>
  
    <script src="js/swfupload.js"></script>
    <script src="js/jquery-asyncUpload-0.1.js"></script>

 <script>
    $(function() {
        $("#yourID").makeAsyncUploader({
            upload_url: "../test1.php", // Important! This isn't a directory, it's a HANDLER such as an ASP.NET MVC action method, or a PHP file, or a Classic ASP file, or an ASP.NET .ASHX handler. The handler should save the file to disk (or database).
            flash_url: 'js/swfupload.swf',  
            file_size_limit: '1024 MB',
            button_image_url: 'js/blankButton.png'
        });
    });        
</script>
<style>
<!--
DIV.ProgressBar { width: 100px; padding: 0; border: 1px solid black; margin-right: 1em; height:.75em; margin-left:1em; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; }
DIV.ProgressBar DIV { background-color: Green; font-size: 1pt; height:100%; float:left; }
SPAN.asyncUploader OBJECT { position: relative; top: 5px; left: 10px; }
-->
<!-- 
</style>
 
<input type="file" id="yourID" name="yourID" />
code for php


 require_once 'system/config/configure.php';    
    $con = mysql_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD);
    mysql_select_db(DB_DATABASE);
         echo "ok";
         define('VIDEO_IMG_FULL_PATH',getcwd()."/upload/");
          $uploaddir = VIDEO_IMG_FULL_PATH;
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadfile)

Tuesday, March 16, 2010

how to increment the column value in mysql?

  We can increment the column value by
  
     UPDATE images SET counter=counter+1 WHERE image_id=15
   where counter is the column name

How to get the last insert id in php

           To get the last id insert in mysql by php by function mysql-insert-id().
This return the last id inserted.
  For more details click here

Saturday, March 6, 2010

To create the frame for code in blogs

This the link where you can create the different frame for code.
http://formatmysourcecode.blogspot.com/

Friday, February 26, 2010

Create thumbnail image in php

This function will create the thumbnail image of the source file
other thing explain in function

function createthumbimage($source_path,$ext,$filename)
    {

          //$ext=extension of file

      
     if ($ext == 'jpg' || $ext == 'jpeg')
     {
      $img = @imagecreatefromjpeg($source_path);
     }
      else if ($ext == 'png')
      {
      $img = @imagecreatefrompng($source_path);
     # Only if your version of GD includes GIF support
     } else if ($ext == 'gif')
     {
      $img = @imagecreatefromgif($source_path);
     }
    
         if ($img)
     {

      # Get image size and scale ratio
      $width = imagesx($img);
      $height = imagesy($img);
      $scale = min(PRODUCT_MAX_WIDTH/$widthPRODUCT_MAX_WIDTH/$height);
     //PRODUCT_MAX_WIDTH and PRODUCT_MAX_WIDTH is predefine width and height of thumbnail image

      # If the image is larger than the max shrink it
     
       $new_width = floor($scale*$width);
       $new_height = floor($scale*$height);
    
       # Create a new temporary image
       $tmp_img = imagecreatetruecolor($new_width, $new_height);
    
       # Copy and resize old image into new image
       imagecopyresized($tmp_img, $img, 0, 0, 0, 0,
            $new_width, $new_height, $width, $height);
       imagedestroy($img);
       $img = $tmp_img;
    
      // $new_filename="";
       imagejpeg($img,PRODUCT_IMG_THUMB_PATH.$filename);

         // PRODUCT_IMG_THUMB_PATH.= this the define path that will put thumb file in define path

      }
   }

Have Dream Day

Tuesday, February 16, 2010

Get file extension in php

The file extension with all details can get below given way


/*** example usage ***/$filename 'filename.blah.txt';//this is file name or any file also can uploaded
/*** get the path info ***/$info pathinfo($filename);//
/*** show the extension ***/echo $info['extenstion'];//
?>

Friday, February 12, 2010

Mysql dump Table for all countries and states

Hi
      This the MySQL dump file contains the list of all country and state respectively,
for that just create the database and import the file.
 Attechment

Have Dream Day