guley
Gulshan@guley

Software Engineer

  • 3 years-4 months

    Copy text to clipboard

    • Category : jquery
    • Location : Chandigarh
    • Posted On : Feb 03, 2017
    • Posted by : Guley

    you can copy text to clipboard and paste where you want

    <button class="btn btn-success" id="copyButton" onclick="copyToClipboard('testing')">Copy</button>
    
    <script type="text/javascript">
    function copyToClipboard(elementId) {
    
      // Create a "hidden" input
      var aux = document.createElement("input");
    
      // Assign it the value of the specified element
      aux.setAttribute("value", elementId);
    
      // Append it to the body
      document.body.appendChild(aux);
    
      // Highlight its content
      aux.select();
    
      // Copy the highlighted text
      document.execCommand("copy");
    
      // Remove it from the body
      document.body.removeChild(aux);
    
    }
    </script>
  • 3 years-4 months

    Prevent auto rotation while uploading in php

    • Category : php
    • Location : Chandigarh
    • Posted On : Jan 25, 2017
    • Posted by : Guley

    You can prevent auto image rotation problem using this code

    function correctImageOrientation($filename) {
      if (function_exists('exif_read_data')) {
        $exif = exif_read_data($filename);
        if($exif && isset($exif['Orientation'])) {
          $orientation = $exif['Orientation'];
          if($orientation != 1){
            $img = imagecreatefromjpeg($filename);
            $deg = 0;
            switch ($orientation) {
              case 3:
                $deg = 180;
                break;
              case 6:
                $deg = 270;
                break;
              case 8:
                $deg = 90;
                break;
            }
            if ($deg) {
              $img = imagerotate($img, $deg, 0);        
            }
            // then rewrite the rotated image back to the disk as $filename 
            imagejpeg($img, $filename, 95);
          } // if there is some rotation necessary
        } // if have the exif orientation info
      } // if function exists      
    }
    
    $target_dir = "blog/";
    $target_file = $target_dir . basename($blogimg);
    $imge=correctImageOrientation($target_file);
    move_uploaded_file($_FILES["blogimg"]["tmp_name"], $imge); 
    $query=mysql_query("insert into tablename (`image_name`) values ('$target_file')");
    
  • 3 years-4 months

    Jquery Change css and background

    • Category : jquery
    • Location : Chandigarh
    • Posted On : Jan 24, 2017
    • Posted by : Guley

    You can change background of container using this code

    Html:
    
    <form class="form-inline">
         <div class="form-group">
          <label for="fileToUpload"> <img src="images/upload.png'; ?> " width="200" height="100" id="blah1" /></label>
           <div class="input-group">
      <input type="file" name="exmaple" id="fileToUpload"  required>
      <input type="hidden" id="backupimgurl" val="">
     </div>
      </div>
            <div class="form-group">
        <div class="input-group">
     <select class="form-control" onchange="$('#home-page').css({'background-position':$(this).val()});" name="BackgroundPosition" id="BackgroundPosition">
        <option value="center" selected="selected">Center</option>
        <option value="center top">Center/Top</option>
        <option value="center bottom">Center/Bottom</option>
        <option value="left center">Left/Center</option>
        <option value="left top">Left/Top</option>
        <option value="left bottom">Left/Bottom</option>
        <option value="right center">Right/Center</option>
        <option value="right top">Right/Top</option>
        <option value="right bottom">Right/Bottom</option>
      </select>
     </div>
     </div>
     <div class="form-group">
      <div class="input-group">
      <select class="form-control" onchange="$('#home-page').css({'background-repeat':$(this).val()});" name="BackgroundImageRepeat" id="BackgroundImageRepeat">
       <option value="repeat-x">Repeat Horizontal</option>
       <option value="repeat-y">Repeat Vertical</option>
       <option value="repeat">Repeat</option>
        <option value="no-repeat" selected="selected">No Repeating</option>
          </select>
      </div>
    </div>
    <div class="form-group">
      <div class="input-group">
       <input class="form-control" value="" name="BackgroundColor" style="width:80%; display:inline-block;" maxlength="6" placeholder="color">
     </div>
      </div>
     <div class="form-group">
     <div class="input-group">
         <button type="submit" class="btn btn-success">Save</button>
         </div>
          <div class="input-group">
         <button type="submit" class="btn btn-danger">Cancel</button>
        </div>
       </div>
    </form>
    
    jQuery:
    
    jQuery(document).on('change','#fileToUpload',function(){
     var imgbg = window.URL.createObjectURL(this.files[0]);
      jQuery('#backupimgurl').val(imgbg);
       //console.log(imgbg);
     jQuery('#home-page').css({backgroundImage: "url(" imgbg ")"});
    });
    
  • 3 years-4 months

    Multiple Image Upload Using Codeigniter

    • Category : php
    • Location : Chandigarh
    • Posted On : Jan 03, 2017
    • Posted by : Guley

    Easy Multiple Image Using Codeigniter.

    if($_FILES['filename']['name']!='')
     {
           $image=array();
           $counts = count($_FILES['filename']['name']);
           $config['upload_path'] = APPPATH.'uploads/'; //create upload folder in application
                                                        // Give permission -R 777 to upload folder 
           $config['allowed_types'] = '*';
           $files = $_FILES;
           for($i=0; $i<$counts; $i  )
            {       
               if($_FILES['filename']['name'][$i]!='')
     { 
           $_FILES['filename']['name']= time().$files['filename']['name'][$i];
           $_FILES['filename']['type']= $files['filename']['type'][$i];
           $_FILES['filename']['tmp_name']= $files['filename']['tmp_name'][$i];
           $_FILES['filename']['error']= $files['filename']['error'][$i];
           $_FILES['filename']['size']= $files['filename']['size'][$i];
           $this->load->library('upload', $config);
           $this->upload->initialize($config);
           $upload= $this->upload->do_upload('familypicture');
           if($upload){
          $uu=$this->upload->data();
                $image[] =$uu['file_name'];
       }
             }
             }
       $fileToUpload = implode('|',$image);
    }
     
  • 3 years-4 months

    Prevent page reload after content changed

    • Category : jquery
    • Location : Chandigarh
    • Posted On : Dec 28, 2016
    • Posted by : Guley

    you can prevent your page if some changes has been done on page.and show warning to user if they won't to leave page

    function enableBeforeUnload() {
        window.onbeforeunload = function (e) {
            return "Discard changes?";
        };
    }
    function disableBeforeUnload() {
        window.onbeforeunload = null;
    }
    $('input, textarea, select').change(function(event){
      enableBeforeUnload();
    });
    /***Using Jquery**/
    $('#formid').submit(function(){
     disableBeforeUnload();
    });
    /***useing html**/
    <form action="" onsubmit="disableBeforeUnload();" method="post>
    //your code
    </form>
  • 3 years-4 months

    Split time interval in 15 min slot

    • Category : php
    • Location : Chandigarh
    • Posted On : Nov 18, 2016
    • Posted by : Guley

    split time interval in 15 min slot using php

    $array_of_time = array ();
    $start_time    = strtotime ("2013-08-28 17:45:00");
    $end_time      = strtotime ("2013-08-28 22:15:00");
    
    $fifteen_mins  = 15 * 60;
    
    while ($start_time <= $end_time)
    {
       $array_of_time[] = date ("Y-m-d H:i:s", $start_time);
       $start_time  = $fifteen_mins;
    }
    
    print_r ($array_of_time);
     
  • 3 years-4 months

    Display Multiple Images Preview

    • Category : jquery
    • Location : Chandigarh
    • Posted On : Oct 21, 2016
    • Posted by : Guley

    When you select multiple images using file input..after taht display all images where you wan't before upload

    <input type='file' name="image" onchange="preview(this);" multiple="multiple" />
    <div id='previewImg'></div>
    
    <script>
    window.preview = function (input) {
        if (input.files && input.files[0]) {
            $(input.files).each(function () {
                var reader = new FileReader();
                reader.readAsDataURL(this);
                reader.onload = function (e) {
                    $("#previewImg").append("<img class='thumb' src='"   e.target.result   "'>");
                }
            });
        }
    }
    </script>
     
  • 3 years-4 months

    Drag Drop multiple divs

    • Category : php
    • Location : Chandigarh
    • Posted On : Sep 30, 2016
    • Posted by : Guley

    you can drag drop all data between multiple divs

     <div id="1" dvSource dvSourceul">
    <ul id="dropul_1">
          <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" /> </li>
    </ul>
        </div>
    <div id="2">
    <ul id="dropul_2">
          <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" />
    <li class="drop"> <img alt="" src="images/Chrysanthemum.jpg" /> </li>
    </ul>
        </div>
    /********Jquery*********
    <script>
     $(function () {
                $("li.drop").draggable({
                    revert: "invalid",
                    refreshPositions: true,
                    drag: function (event, ui) {
                        ui.helper.addClass("draggable");
                       
                    },
                    stop: function (event, ui) {
                        if ($.ui.ddmanager.drop(ui.helper.data("draggable"), event)) {
                             ui.helper.removeClass("ui-draggable-dragging");
                             ui.helper.removeClass("draggable");
                        }
                        else {
                            //alert(" not dropped.");
                        }
                    }
                });
                $(".dvSourceul").droppable({
                    drop: function (event, ui ) {
                      var newId=event.target.id;
                      var aworkid=ui.draggable.attr('data-id');
                        ui.draggable.addClass("dropped");
                        $("#dropul_" newId).append(ui.draggable);
                        $.ajax({
                          type: "POST",
                          url: "update_work.php",
                          data:'id=' aworkid '&wrkid=' newId,
                          success: function(data){
                          // alert(data);
                          }
                          });
                    }
                });
            });
    
    </script>
  • 3 years-4 months

    Image Compress

    • Category : php
    • Location : Chandigarh
    • Posted On : Aug 17, 2016
    • Posted by : Guley

    COmpress your image size using php

    <?php
     $name = ''; $type = ''; $size = ''; $error = '';
      function compress_image($source_url, $destination_url, $quality) {
    
        $info = getimagesize($source_url);
    
            if ($info['mime'] == 'image/jpeg')
                  $image = imagecreatefromjpeg($source_url);
    
            elseif ($info['mime'] == 'image/gif')
                 $image = imagecreatefromgif($source_url);
    
           elseif ($info['mime'] == 'image/png')
                 $image = imagecreatefrompng($source_url);
    
           imagejpeg($image, $destination_url, $quality);
        return $destination_url;
      }
    
     if ($_POST) {
    
           if ($_FILES["file"]["error"] > 0) {
                  $error = $_FILES["file"]["error"];
            } 
            else if (($_FILES["file"]["type"] == "image/gif") || 
         ($_FILES["file"]["type"] == "image/jpeg") || 
         ($_FILES["file"]["type"] == "image/png") || 
          ($_FILES["file"]["type"] == "image/pjpeg")) {
    
                 $url = 'destination .jpg';
    
                  $filename = compress_image($_FILES["file"]["tmp_name"], $url, 80);
                  $buffer = file_get_contents($url);
    
                  /* Force download dialog... */
                  header("Content-Type: application/force-download");
                 header("Content-Type: application/octet-stream");
                 header("Content-Type: application/download");
    
         /* Don't allow caching... */
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    
                  /* Set data type, size and filename */
                  header("Content-Type: application/octet-stream");
                 header("Content-Transfer-Encoding: binary");
                  header("Content-Length: " . strlen($buffer));
                 header("Content-Disposition: attachment; filename=$url");
    
                 /* Send our file... */
                  echo $buffer;
           }else {
                 $error = "Uploaded image should be jpg or gif or png";
            }
     }
    ?>
    <html>
          <head>
                <title>Php code compress the image</title>
          </head>
         <body>
    
        <div class="message">
                         <?php
                            if($_POST){
                               if ($error) {
                                   ?>
                                   <label class="error"><?php echo $error; ?></label>
                            <?php
                                    }
                             }
                         ?>
                     </div>
        <fieldset class="well">
                       <legend>Upload Image:</legend>                
          <form action="" name="myform" id="myform" method="post" enctype="multipart/form-data">
            <ul>
                        <li>
                <label>Upload:</label>
                                          <input type="file" name="file" id="file"/>
              </li>
             <li>
                <input type="submit" name="submit" id="submit" class="submit btn-success"/>
             </li>
           </ul>
         </form>
       </fieldset>
     </body>
    </html>
     
  • 3 years-4 months

    Drag drop

    • Category : php
    • Location : Chandigarh
    • Posted On : Aug 17, 2016
    • Posted by : Guley

    Drag Drop your table's data using jQuery,Ajax,php and mysql

    /**********HTML PART START**************/
    
    <div class="x_content my-data" id="">
    
                      <table class="table table-bordered">
                        <thead>
                          <tr>
                            <th>#</th>
                            <th>Image</th>
                            <th>Category</th>
                            <th>Edit</th>
                            <th>Delete</th>
                          </tr>
                        </thead>
    <?php
      
      $query = "SELECT * FROM product ORDER BY pos ASC";
      $result = mysql_query($query) or die(mysql_error().': '.$query);
      if(mysql_num_rows($result)) {
    ?>
    <form id="dd-form" action="" method="post">
      <input type="checkbox" value="1" name="autoSubmit" id="autoSubmit" class="autoooo" checked/>
    <tbody id="sortable-list">
      <?php 
        $order = array();
        $i=1;
        while($row = mysql_fetch_assoc($result)) {
            $img=explode(",",$row['product_img']);
                           $img=explode(",",$row['product_img']);
    $catqry=mysql_fetch_array(mysql_query("select * from category where id='".$row['product_cat_id']."'"));
    $scatqry=mysql_fetch_array(mysql_query("select * from subcategory where id='".$row['product_subcat_id']."'"));
    
                           echo '<tr title="',$row['id'],'"><td>',$i,'</td><td><img src="',$img[0],'" height="50" width="50"></td><td>',$catqry['cat_name_eng'].'/'.$catqry['cat_name_china'],'</td><td><a href="?edit=',$row['id'],'"><i class="fa fa-pencil"></i></a></td><td><a href="?delete=',$row['id'],'" onclick="return confirm("Are you sure you want to delete")"><i class="fa fa-trash"></i></a></td></tr>';
          $order[] = $row['id'];
          $i  ;
        }
      ?>
    </tbody>
    <br />
    <input type="hidden" name="sort_order" id="sort_order" value="<?php echo implode(',',$order); ?>" />
    </form>
    <?php } ?>
    
    
                      </table>
    
                    </div>
                  </div>
            
            </div>
    <style type="text/css" media="screen">
    #sortable-list1   { padding:0; }
    #sortable-list1 tr  { padding:4px 8px; color:#000; cursor:move; list-style:none; width:100px; background:#ddd; margin:10px 0; border:1px solid #999; }
    #sortable-list1 tr td { text-align: center; }
    #message-box1   { padding:4px 8px; margin:0 0 14px 0; width:500px; }
    .autoooo{ display : none; }
    </style>
    /**********HTML PART END**************/
    /**********SCRIPT PART START**************/
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
      <script>
    /* when the DOM is ready */
    $(document).ready(function() {
    
      /* grab important elements */
      var sortInput = $('#sort_order');
      var submit = $('#autoSubmit');
      var messageBox = $('#message-box');
      var list = $('#sortable-list');
      /* create requesting function to avoid duplicate code */
      var request = function() {
      $.ajax({
      url: "drop_ajax.php",
      data:'sort_order='   sortInput[0].value   '&ajax='   submit[0].checked   '&do_submit=1&byajax=1',
      type: "POST",
      success: function(data) {
            window.location.reload();
      }
      });
      };
      /* worker function */
      var fnSubmit = function(save) {
       
        var sortOrder = [];
        list.children('tr').each(function(e){
          sortOrder.push($(this).data('id'));
        });
        sortInput.val(sortOrder.join(','));
       // console.log(sortInput.val());
        if(save) {
          request();
        }
      };
      /* store values */
      list.children('tr').each(function(e) {
        var tr = $(this);
        tr.data('id',tr.attr('title')).attr('title','');
      });
      /* sortables */
      list.sortable({
        opacity: 0.7,
        update: function() {
          fnSubmit(true);
        }
      });
      list.disableSelection();
    });
    </script>
    /**********SCRIPT PART END**************/
    /**********AJAX PART START**************/
    <?php
    include('config.php'); /include your db file here
    /* on form submission */
    if(isset($_POST['do_submit']))  {
      /* split the value of the sortation */
      $ids = explode(',',$_POST['sort_order']);
     /* run the update query for each id */
      foreach($ids as $index=>$id) {
       $id = (int) $id;
        if($id != '') {
         $query = 'UPDATE product SET pos = '.($index   1).' WHERE id = '.$id;
         $result = mysql_query($query) or die(mysql_error().': '.$query);
        }
     }
     
      /* now what? */
     if($_POST['byajax']) { die(); } else { $message = 'Sortation has been saved.'; 
     
      echo $message;
      }
    }
    ?>
    
    
    /**********AJAX PART END**************/
No items found