Top Questions

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Aug 18, 2016

    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>
     
  • 2.9 Years

    • Category : Wordpress
    • Location : Chandigarh
    • Posted On : Mar 8, 2016
    <?php
    $deptID = "7";
    $childCatID = $wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent=$deptID");
    if ($childCatID){
    foreach ($childCatID as $kid)
    {
    $childCatName = $wpdb->get_row("SELECT name, term_id FROM $wpdb->terms WHERE term_id=$kid");
    echo $childCatName->term_id;
    echo $childCatName->name;
    }
    ?>

     

  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Mar 16, 2016
    <?php 
    include('config.php'); //connection file
    //header to give the order to the browser
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment;filename=user.csv');
    //select table to export the data
    $select_table=mysql_query('select `email` from login');
    $rows = mysql_fetch_assoc($select_table);
    
    if ($rows)
    {
    getcsv(array_keys($rows));
    }
    while($rows)
    {
    getcsv($rows);
    $rows = mysql_fetch_assoc($select_table);
    }
    
    // get total number of fields present in the database
    function getcsv($no_of_field_names)
    {
    $separate = '';
    
    
    // do the action for all field names as field name
    foreach ($no_of_field_names as $field_name)
    {
    /*if (preg_match('/\\r|\\n|,|"/', $field_name))
    {
    $field_name = '' . str_replace('', $field_name) . '';
    }*/
    echo $separate . $field_name;
    
    //sepearte with the comma
    $separate = ',';
    }
    
    //make new row and line
    echo "\r\n";
    }
    ?>

     

  • 2.9 Years

    • Category : Wordpress
    • Location : Chandigarh
    • Posted On : Mar 8, 2016
    <?php
        global $post;
        $args = array( 'numberposts' => 10, 'category' => 6 );
        $posts = get_posts( $args );
        foreach( $posts as $post ): setup_postdata($post); 
    ?>
    
        <divs with the_title() the_excerpt() etc ></div>
    
    <?php 
        endforeach; 
    ?>

     

  • 5.11 Years

    • Category : Magento
    • Location : Mohali
    • Posted On : Jul 7, 2016

    Magento SEO - How to add Magento Canonical Meta Tag

    Step 1: Login your Magento Admin Panel

    Step 2: Go to  System > Configuration

    Step 3: In the left menu, choose Catalog >> Search Engine Optimizations
    • In the "Use Canonical Link Meta Tag for Categories" choose "Yes"
    • In the "Use Canonical Link Meta Tag for Products" choose "No"

    Step 4:  Save the changes
     
  • 5.11 Years

    • Category : Java
    • Location : Mohali
    • Posted On : Jul 9, 2016

    URL — The new history entry's URL is given by this parameter. Note that the browser won't attempt to load this URL after a call to pushState(), but it might attempt to load the URL later, for instance after the user restarts the browser. The new URL does not need to be absolute; if it's relative, it's resolved relative to the current URL. The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception. This parameter is optional; if it isn't specified, it's set to the document's current URL.

    // modify history
    window.history.pushState(obj, title, url);
    window.history.pushState("", "", 'www.dorcode.com');  
  • 2.9 Years

    • Category : Wordpress
    • Location : Chandigarh
    • Posted On : Mar 9, 2016
    /**
     * Register a custom menu page.
     */
    function wpdocs_register_my_custom_menu_page() {
        add_menu_page(
            __( 'Bookings', 'textdomain' ),
            'Bookings',
            'manage_options',
            'admin.php?page=booking_diplay',
            'booking_display',
            plugins_url( 'bookin1.png' ),
            6
        );
    }
    add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );
    function booking_display()
    {
     require_once(plugin_dir_path(__FILE__).'booking_display.php');
    }

     

  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : Aug 14, 2015

    After wordpress login redirect page but not refresh so please try to add these lines in the top of the your wordpress theme file like header.php or wp-config.php https://www.youtube.com/watch?v=ItTjUrTZ_JE

    <?php
    str = "Hello world. It's a beautiful day.";
    print_r (explode(" "$str));
    ?>
    

    1 Answers

    View More
  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : May 29, 2018

    default WooCommerce if the user clicks on the add to cart button, that item is added to the cart. if you want to add custom add to cart button please remove default "add to cart" button

    // custom template
    <button type="submit" class="custom_cart_button">add to cart</button>
    <script type="text/javascript">
    jQuery(document).ready(function() {
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
        jQuery('.custom_cart_button').submit(function(e) {
            jQuery.ajax({
                url: ajaxurl,
                type: "post",
                data: {				
    		action : 'post_product_variations19'
    	    },
                success: function(data) {   
                	console.log(data);
                }
            });
    	return false;
        });
    });
    </script>
    
    
    // function.php
    add_action( 'wp_ajax_nopriv_post_product_variations19', 'post_product_variations_func19' );
    add_action( 'wp_ajax_post_product_variations19', 'post_product_variations_func19' );
    function post_product_variations_func19() {
    
        global $woocommerce;
    
        $product_id = 364; // your product id
    
        $found = false;
    
        //check if product already in cart
        if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
            foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id ) {
                	//$calc_qty = $values['quantity'] < 1 ? 1 : $values['quantity']+1;
                	//$woocommerce->cart->set_quantity( $cart_item_key, $calc_qty, true );
                    $found = true;
                }
            }
            // if product not found, add it
            //if ( ! $found )
                $woocommerce->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            $woocommerce->cart->add_to_cart( $product_id );
        }
    	
    wp_die();
    }
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Jun 5, 2016

    Display limited o of word from a string using this code

    echo mb_strimwidth('It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English', 0, 50, "...");