php (tp5) generating a two-dimensional code

phpqrcode library official website Download: https://sourceforge.net/projects/phpqrcode/

 

1. We take a look at php is how to generate two-dimensional code

  

  1. First, let's look at phpqrcode download library.

 

  2. Once downloaded decompress we will find  phpqrcode folder   there are a bunch of files, but we just need to find phpqrcode.php file copy, with the   index.php file can be put together, and index.php is that you generate two-dimensional code php code.

  

  3. The next step is a part of the code, copy paste the following code to execute php file saved, you will find in the index.php file there will be more of a folder, opening the inside you will find what you want the two-dimensional code.

  

? < PHP 

// generate two-dimensional code 
function userimg () { 
    
  // introduced phpqrcode library file 
  require_once 'phpqrcode.php' ; 

  $ value = 'https://www.cnblogs.com/junyi-bk/';          // two-dimensional code contents 
  $ errorCorrectionLevel = 'L';   // fault-tolerance level of 
  $ matrixPointSize = 5;       // generated image size 

  // determine whether there is not, then this folder will create an 
  iF (! is_dir ( "qrcode" )) {
     / / create a file plus 
    mkdir ( "qrcode" ); 
  } 

  // set the two-dimensional code image name and storage path 
  $ filename = 'qrcode /'.time. () RAND (10000,9999999) 'PNG.'. ; 
  
  // use the library to generate a two-dimensional code 
  QRcode :: PNG ( $ value , $ filename , $ errorCorrectionLevel , $ matrixPointSize , 2 ); 
  
  // two-dimensional code path 
  return  $ filename ; 
  
} 

// call the two-dimensional code generation method of 
echo userimg ();

 

2. The above is pure php method of generating two-dimensional code, and then we take a look at how the use tp5 generate two-dimensional code

 

  1. First, let's look at phpqrcode download library, it is still the same, need to use phpqrcode library.

 

  2. Remove phpqrcode.php, then placed inside the folder vendor (vendor effect is to put the third-party libraries)

  

  3. The preparations are done, the next step is part of the code, and only need to write and call the following method in the controller inside, you can see a two-dimensional code you want

  

    // two-dimensional code 
    public  function UserImg () { 

        Vendor ( 'phpqrcode'); // introduced libraries 
        $ value = 'https://www.cnblogs.com/junyi-bk/';          // two-dimensional code content 
        $ errorCorrectionLevel = 'L';   // fault-tolerance level of 
        $ matrixPointSize = 5;       // generated image size 
        // generate two-dimensional code picture 
        // determine whether there is not, then this folder will create an 
        iF (! is_dir ( "qrcode" )) {
             // Create a file plus 
            mkdir ( "qrcode" ); 
        } 
        // set two-dimensional code file name 
        $ filename = 'qrcode /'.time. () RAND (10000,9999999) 'PNG.'. ;
         // generate two-dimensional code 
        \ QRcode :: PNG ( $ value , $ filename , $ errorCorrectionLevel , $ matrixPointSize , 2 ); 

        // Get the current domain name 
        $ Request = :: the Request instance ();
         $ Domain = $ Request -> Domain (); 
     
        return  $ Domain '/'.. $ filename ; 
    }        

 

Guess you like

Origin www.cnblogs.com/junyi-bk/p/11577237.html