This article mainly introduces the PHP two-dimensional code production and download implementation code, with a certain reference value, interested in small partners can refer to
The example of this article for you to share the PHP two-dimensional code generation and download the specific code for your reference, the specific content as follows
<?php//introduction of Phpqrcode Library file define (' In_ecs ', true); Require (DirName (__file__). '/includes/init.php '); include (' includes/phpqrcode.php '); QR code data $data = ' http://www.baidu.com '; $filename = ' shopewm/'. ' Baidu.png '; Down_file (' Baidu.png ', Base_path); Setshopewm ($data, $filename); Generate two-dimensional code picture function setshopewm ($data, $filename) {//Error correction level: L, M, Q, H $errorCorrectionLevel = ' L '; The size of the point: 1 to $matrixPointSize = 4; Create a QR code file QRCode::p ng ($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2); Enter QR code to browser//qrcode::p ng ($data);} Download QR code picture function Down_file ($file _name) {$file _sub_dir = str_replace (' \ \ ', '/', Realpath (dirname). ' /'))." /shopewm/"; Reason PHP file functions, older, need to Chinese transcoding gb2312 $file _name=iconv ("Utf-8", "gb2312", $file _name); Absolute path $file _path= $file _sub_dir. $file _name; 1. Open File if (!file_exists ($file _path)) {echo "file does not exist!"; return; } $fp =fopen ($file _path, "R"); 2. Processing the file//Get the size of the downloaded file $file _size=filesize ($file _path); /* if ($file _size>30) {echo "<script language= ' jaVascript ' >window.alert (' too big ') </script> "; return; } *///The header of the file returned ("Content-type:application/octet-stream"); Returns the header ("Accept-ranges:bytes") by byte size; Returns the file size header ("Accept-length: $file _size"); Here the client's popup dialog box, corresponding to the filename header ("content-disposition:attachment; Filename= ". $file _name); Loopback data to the client $buffer = 1024; In order to download the security, we'd better make a file byte read counter $file _count=0; This sentence is used to determine if the file is over while (!feof ($fp) && ($file _size-$file _count>0)) {$file _data=fread ($fp, $buffer); Statistics read how many bytes $file _count+= $buffer; Send some data back to the browser; echo $file _data; }//Close file fclose ($FP); }