• php二维码的生产以及下载


    <?php
     
    //引入phpqrcode库文件
    define('IN_ECS', true);
     
    require(dirname(__FILE__) . '/includes/init.php');
    include('includes/phpqrcode.php');
     
    // 二维码数据
    $filename = 'shopEwm/'.'baidu.png';
     
    //down_file('baidu.png',BASE_PATH);
    setShopEwm($data,$filename);
     
    //生成二维码图片
    function setShopEwm($data,$filename){
    // 纠错级别:L、M、Q、H
     
        $errorCorrectionLevel = 'L';
        // 点的大小:1到10
        $matrixPointSize = 4;
        //创建一个二维码文件
        QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
        //输入二维码到浏览器
        //QRcode::png($data);
    }
    //下载二维码图片
    function down_file($file_name){
        $file_sub_dir = str_replace('\','/',realpath(dirname(__FILE__).'/'))."/shopEwm/";
        //原因 php文件函数,比较古老,需要对中文转码 gb2312
        $file_name=iconv("utf-8","gb2312",$file_name);
     
        //绝对路径
        $file_path=$file_sub_dir.$file_name;
        //1.打开文件
        if(!file_exists($file_path)){
            echo "文件不存在!";
            return ;
        }
     
        $fp=fopen($file_path,"r");
        //2.处理文件
        //获取下载文件的大小
        $file_size=filesize($file_path);
     
        /* if($file_size>30){
     
        echo "<script language='javascript'>window.alert('过大')</script>";
        return ;
        } */
     
        //返回的文件
        header("Content-type: application/octet-stream");
        //按照字节大小返回
        header("Accept-Ranges: bytes");
        //返回文件大小
        header("Accept-Length: $file_size");
        //这里客户端的弹出对话框,对应的文件名
        header("Content-Disposition: attachment; filename=".$file_name);
     
        //向客户端回送数据
     
        $buffer=1024;
        //为了下载的安全,我们最好做一个文件字节读取计数器
        $file_count=0;
        //这句话用于判断文件是否结束
        while(!feof($fp) && ($file_size-$file_count>0) ){
            $file_data=fread($fp,$buffer);
            //统计读了多少个字节
            $file_count+=$buffer;
            //把部分数据回送给浏览器;
            echo $file_data;
        }
     
        //关闭文件
        fclose($fp);
     
    }
  • 相关阅读:
    Java编程的逻辑 (62)
    float示例
    如何避免在短时间内按钮被多次重复点击
    前端(jQuery)(9)-- jQuery菜单
    前端(jQuery)(8)-- jQuery元素遍历
    前端(jQuery)(6)-- jQuery的扩展与noConflict
    前端(jQuery)(5)-- jQuery AJAX异步访问和加载片段
    xampp中tomcat服务器无法启动
    前端(jQuery)(4)-- jQuery隐藏显示与淡入淡出、滑动、回调
    自定义事件总结
  • 原文地址:https://www.cnblogs.com/xiatian0721/p/7606161.html
Copyright © 2020-2023  润新知