Php Flow » Php

Barcode Generation in PHP and With Help of Curl

Here Now we have discuss how to generate barcode in PHP and use in different manner.I have taken reverence from ashberg blog.
First you download the barcode file From here :
When you save downloaded zip file and extract it.Now You are able to run this code .Here you have get file barcode.php which main index file for generating bar code ,which is show only the barcode generated image.

Option 1:May be You need to download the barcode generated image

 Find the below code in php-barcode.php

  1. $mode=strtolower($mode);    
  2. if ($mode==’jpg’ || $mode==’jpeg’){    
  3. header(“Content-Type: image/jpeg; name=\”barcode.jpg\””);    
  4. imagejpeg($im);    
  5. else if ($mode==’gif’){    
  6. header(“Content-Type: image/gif; name=\”barcode.gif\””);    
  7. imagegif($im);    
  8. else {    
  9. header(“Content-Type: image/png; name=\”barcode.png\””);    
  10. imagepng($im);    
  11. }    

And replace above code from nelow code for download image:

  1. if ($mode==’jpg’ || $mode==’jpeg’){  
  2. header(“Content-Disposition: attachment; filename=p1.jpeg”);  
  3. imagejpeg($im);  
  4. else if ($mode==’gif’){  
  5. header(“Content-Type: image/gif; name=\”barcode.gif\””);  
  6. imagegif($im);  
  7. else {  
  8. header(“Content-Type: image/png; name=\”barcode.png\””);  
  9. imagepng($im);  
  10. }  

Option 2:May be You need to save the image on folder

Then replace above code from below code,here You will see a$save location it’s the location where you save the generated barcode image.

  1. $mode=strtolower($mode);    
  2. if ($mode==‘jpg’ || $mode==‘jpeg’){    
  3. $save_loc =“uploads/barcode6.jpg”;    
  4. echo”    
  5. <h1>barcode created</h1>    
  6. .$save_loc”;    
  7. header(“Content-Type: image/jpeg; name=\”barcode.jpg\””);    
  8. $save_loc =$save_loc.“barcode.jpg”;    
  9. imagejpeg($im,$save_loc);    
  10. else if ($mode==‘gif’){    
  11. $save_loc =“uploads/barcode6.gif”;    
  12. echo”    
  13. <h1>barcode created</h1>    
  14. .$save_loc”;    
  15. header(“Content-Type: image/gif; name=\”barcode.gif\””);    
  16. $save_loc =$save_loc.“barcode.gif”;    
  17. imagegif($im,$save_loc);    
  18. else {    
  19. $save_loc =“uploads/barc_”.$image_name.“.png”;    
  20. echo”    
  21. <h1>barcode created</h1>    
  22. Check at $save_loc”;    
  23. header(“Content-Type: image/png; name=\”barcode.png\””);    
  24. //$save_loc =$save_loc ;    
  25. imagepng($im,$save_loc);    
  26. }    

Option 3:How to generate barcode with help of Curl .

1. First intilozed the curl with following code

  1. $ch = curl_init();  

2. Now call the curl method with specific URL

  1. curl_setopt($ch, CURLOPT_URL,“http://localhost/magento/barcode/barcode.php?code=$strcode”);  

3. Excute the file

  1. curl_exec ($ch);  

4. Close the curl connection

  1. curl_close ($ch);  

Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook.

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>