荟萃馆

位置:首页 > 计算机 > php语言

PHP学习:QRCode PHP生成二维码类库

php语言1.6W

在PHP语言中怎么生成二维码类库呢?下面就和小编一起来看看吧!希望对大家有用,更多内容请关注应届毕业生网!

PHP学习:QRCode PHP生成二维码类库

  使用类库的方法
123include("Common/");$QRCode=newQRCode();$categoryList=$QRCode->getUrl();
  以下是php生成二维码完整类库
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354<?php/***类功能:将指定URL利用googleapi生成二维码保存到本地并返回本地访问url*author:*使用方法见:*/classQRCode{private$path;private$size;publicfunction__construct($path,$size){$this->path=empty($path)?C('webPath')."/Uploads/QRCode/":$path;$this->size=empty($size)?80:$size;}/***检测存储目录是否存在,不存在则创建该目录*/privatefunctionmakeDir($path){returnis_dir($path)or($this->makeDir(dirname($path))and@mkdir($path,0777));}/***取得二维码地址*/publicfunctiongetUrl($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;}}}?>