本文實例為大家分享了php二維碼生成以及下載的具體代碼,供大家參考,具體內容如下
<?php //引入phpqrcode庫文件 define('IN_ECS', true); require(dirname(__FILE__) . '/includes/init.php'); include('includes/phpqrcode.php'); // 二維碼數據 $data = 'http://www.baidu.com'; $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); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持。
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。