YouTube Icon

Code Playground.

How to Generate Barcode Generator using PHP

CFG

How to Generate Barcode Generator using PHP

Barcode is a machine-readable code within the form of numbers and a sample of parallel lines of varying widths. Barcodes are regularly used to help organize and index facts or expenses approximately an item. The Barcode is very beneficial for immediate-promoting gadgets to perceive gadgets speedy and also useful to control inventory to save you stock construct-up for sluggish promoting gadgets. As the Barcode is very beneficial and had to implement in lots of PHP tasks to manipulate inventories and so forth. In this academic, we are able to explain a way to Generate Barcode Generator using PHP. This is a very simple instance, you can simply replica-paste, and change in line with your requirement.

 Download Barcode generate PHP library to create Barcode.

Before commenced to enforce the Generate Barcode Generator using PHP, look files shape:

  •  generate-barcode-using-php
    •  css
      •  style.css
    •  vendor
    •  templates
      •  header.php
      •  footer.php
    •  index.php
    •  function.php

Create Barcode Generate Form record named index.Personal home page

<?php
function generateBarcode($data, $folder) {

    // include QR Codes Lib
    require ('vendor/autoload.php');

    //set it to writable location, a place for temp generated PNG files
    $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.$folder.DIRECTORY_SEPARATOR;
    
    //html PNG location prefix
    $PNG_WEB_DIR = $folder.'/';

    //ofcourse we need rights to create temp dir
    if (!file_exists($PNG_TEMP_DIR))
        mkdir($PNG_TEMP_DIR);
    $timestamp = time();
    $filename = $PNG_TEMP_DIR.$timestamp.'.png';

    $MRP = $data["mrp"];
    $SKU = $data["sku"];
    $MODEL = $data["model"];

    $productData = "098{$MRP}10{$SKU}55{$MODEL}";
    $barcode = new \Com\Tecnick\Barcode\Barcode();
    $bobj = $barcode->getBarcodeObj('C128B', "{$productData}", 450, 70, 'black', array(0, 0, 0, 0));
    
    $imageData = $bobj->getPngData();
    
    file_put_contents($filename, $imageData);

    return $filename;
}
?>

Generate Barcode Function report named function.Personal home page

<?php
function generateBarcode($data, $folder) {

    // include QR Codes Lib
    require ('vendor/autoload.php');

    //set it to writable location, a place for temp generated PNG files
    $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.$folder.DIRECTORY_SEPARATOR;
    
    //html PNG location prefix
    $PNG_WEB_DIR = $folder.'/';

    //ofcourse we need rights to create temp dir
    if (!file_exists($PNG_TEMP_DIR))
        mkdir($PNG_TEMP_DIR);
    $timestamp = time();
    $filename = $PNG_TEMP_DIR.$timestamp.'.png';

    $MRP = $data["mrp"];
    $SKU = $data["sku"];
    $MODEL = $data["model"];

    $productData = "098{$MRP}10{$SKU}55{$MODEL}";
    $barcode = new \Com\Tecnick\Barcode\Barcode();
    $bobj = $barcode->getBarcodeObj('C128B', "{$productData}", 450, 70, 'black', array(0, 0, 0, 0));
    
    $imageData = $bobj->getPngData();
    
    file_put_contents($filename, $imageData);

    return $filename;
}
?>

Create documents named (header.Hypertext Preprocessor and footer.Php)

This file consists of the header and footer phase of the website. The Bootstrap library is used to provide a higher UI, so, encompass it inside the header and footer section.

Header.Hypertext Preprocessor

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>Integrate CCAvenue Payment Gateway using PHP | Tech Arise</title>
  <link rel="icon" type="image/ico" href="https://techarise.com/wp-content/themes/v1/favicon.ico">
  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" />
  <!-- Custom fonts for this template -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.2/css/all.min.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css" />
  <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
  <!-- Custom styles for this template -->
  <link href="css/style.css" rel="stylesheet">
</head>
<body>
  <!-- Navigation -->
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top header-bg-dark" style="background: ##FFFFFF!;">
  <div class="container">
    <a class="navbar-brand font-weight-bold" href="https://techarise.com"><h1>Tech Arise</h1></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link" href="https://techarise.com">Home
                <span class="sr-only">(current)</span>
              </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="https://techarise.com/php-free-script-demos/">Live Demo</a>
        </li>
      </ul>
    </div>
  </div>
</nav>  

footer.Personal home page

<!-- Footer -->
  <footer class="footer bg-light footer-bg-dark">
    <div class="container">
      <div class="row">
        <div class="col-lg-6 h-100 text-center text-lg-left my-auto">
          <ul class="list-inline mb-2">
            <li class="list-inline-item">
              <a href="#">About</a>
            </li>
            <li class="list-inline-item">&sdot;</li>
            <li class="list-inline-item">
              <a href="#">Contact</a>
            </li>
            <li class="list-inline-item">&sdot;</li>
            <li class="list-inline-item">
              <a href="#">Terms of Use</a>
            </li>
            <li class="list-inline-item">&sdot;</li>
            <li class="list-inline-item">
              <a href="#">Privacy Policy</a>
            </li>
          </ul>
          <p class="text-muted small mb-4 mb-lg-0">Copyright &copy;  2011 - <?php print date('Y', time());?> <a href="https://techarise.com/">TECHARISE.COM</a> All rights reserved.</p>
        </div>
        <div class="col-lg-6 h-100 text-center text-lg-right my-auto">
          <ul class="list-inline mb-0">
            <li class="list-inline-item mr-3">
              <a href="#">
                <i class="fab fa-facebook fa-2x fa-fw"></i>
              </a>
            </li>
            <li class="list-inline-item mr-3">
              <a href="#">
                <i class="fab fa-twitter-square fa-2x fa-fw"></i>
              </a>
            </li>
            <li class="list-inline-item">
              <a href="#">
                <i class="fab fa-instagram fa-2x fa-fw"></i>
              </a>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </footer>
  <!-- Bootstrap core JavaScript -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>  
</body>
</html>

 




CFG