How PHP implements the generation of QR codes and download cases

Source: Internet
Author: User
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); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.