在PHP语言中怎么生成二维码类库呢?下面就和小编一起来看看吧!希望对大家有用,更多内容请关注应届毕业生网!
使用类库的方法
123 | include ( "Common/" ); $QRCode = new QRCode(); $categoryList = $QRCode ->getUrl(); |
以下是php生成二维码完整类库
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | <?php
class QRCode{
private $path ;
private $size ;
public function __construct( $path , $size ){
$this ->path= empty ( $path )?C( 'webPath' ). "/Uploads/QRCode/" : $path ;
$this ->size= empty ( $size )?80: $size ;
}
private function makeDir( $path ){
return is_dir ( $path ) or ( $this ->makeDir(dirname( $path )) and @ mkdir ( $path ,0777));
}
public function getUrl( $url = "" ){
$inPath = '#39; . $this ->size. 'x' . $this ->size. '&cht=qr&chld=L|0&chl=' . $url ;
$savePath = $_SERVER [ 'DOCUMENT_ROOT' ]. $this ->path;
$this ->makeDir( $savePath );
$fileName = substr (md5( "$url" ),8,16). "_" . $this ->size. ".png" ;
$savePath .= $fileName ;
$outUrl = "http://" . $_SERVER [ 'HTTP_HOST' ]. $this ->path. $fileName ;
if ( file_exists ( $savePath )&& filesize ( $savePath )>0){
return $outUrl ;
}
$in = fopen ( $inPath , "rb" );
$out = fopen ( $savePath , "wb" );
while ( $chunk = fread ( $in ,8192))
fwrite( $out , $chunk ,8192);
fclose( $in );
fclose( $out );
if ( filesize ( $savePath )==0){
$this ->getUrl( $url );
} else {
return $outUrl ;
}
}
}
?> |