欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php二維碼生成以及下載實(shí)現(xiàn)

 更新時(shí)間:2017年09月28日 14:09:24   作者:夏天0721  
這篇文章主要介紹了php二維碼生產(chǎn)以及下載實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了php二維碼生成以及下載的具體代碼,供大家參考,具體內(nèi)容如下

<?php
 
//引入phpqrcode庫文件
define('IN_ECS', true);
 
require(dirname(__FILE__) . '/includes/init.php');
include('includes/phpqrcode.php');
 
// 二維碼數(shù)據(jù)
$data = 'http://www.baidu.com';
$filename = 'shopEwm/'.'baidu.png';
 
//down_file('baidu.png',BASE_PATH);
setShopEwm($data,$filename);
 
//生成二維碼圖片
function setShopEwm($data,$filename){
// 糾錯(cuò)級別:L、M、Q、H
 
  $errorCorrectionLevel = 'L';
  // 點(diǎn)的大?。?到10
  $matrixPointSize = 4;
  //創(chuàng)建一個(gè)二維碼文件
  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文件函數(shù),比較古老,需要對中文轉(zhuǎn)碼 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");
  //按照字節(jié)大小返回
  header("Accept-Ranges: bytes");
  //返回文件大小
  header("Accept-Length: $file_size");
  //這里客戶端的彈出對話框,對應(yīng)的文件名
  header("Content-Disposition: attachment; filename=".$file_name);
 
  //向客戶端回送數(shù)據(jù)
 
  $buffer=1024;
  //為了下載的安全,我們最好做一個(gè)文件字節(jié)讀取計(jì)數(shù)器
  $file_count=0;
  //這句話用于判斷文件是否結(jié)束
  while(!feof($fp) && ($file_size-$file_count>0) ){
    $file_data=fread($fp,$buffer);
    //統(tǒng)計(jì)讀了多少個(gè)字節(jié)
    $file_count+=$buffer;
    //把部分?jǐn)?shù)據(jù)回送給瀏覽器;
    echo $file_data;
  }
 
  //關(guān)閉文件
  fclose($fp);
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論