在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
请求export_csv.php时如果合法用户就会弹出下面这样的保存下载框:
代码如下:
<?php
require_once('main.php'); if($_COOKIE['CRM_UID'] == null){ showmessage("非法用户!","login.php",1250,'icon_error.jpg'); } if($_COOKIE['CRM_TYPE'] == 4){ showmessage( "您没有权限!", 'index.php?file=online', 1250, 'icon_error.jpg'); } $type = $_GET['t']; export_csv($type); /** *导出到CSV文件 * @param <type> $type */ function export_csv($type) { $filename = date('YmdHis').".csv"; header("Content-type:text/csv"); header("Content-Disposition:attachment;filename=".$filename); header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Expires:0'); header('Pragma:public'); echo array_to_string(get_export_data($type)); } /** *导出数据转换 * @param <type> $result */ function array_to_string($result) { if(empty($result)){ return i("没有符合您要求的数据!^_^"); } $data; $size_result = sizeof($result); for($i = 0 ; $i < $size_result ; ++ $i) { $data .= i($result[$i]['orderID']).','.i($result[$i]['username'])."\n"; } return $data; } /** *获取导出报表的数据 * @param <type> $condition * @return <type> */ function get_export_data($condition) { $where = " state = 0 "; switch($condition) { case 'week': $where .= " and week(date) = week(current_date()-1 ) ;";//每周从周一开始 break; case 'month': $where .= " and month(date) = month(current_date()) ;"; break; case 'year': $where .= " and year(date) = year(current_date()) ;"; break; default: break; } $sql = " select * from net_order_detail where {$where}"; $db = get_db(); $res = $db->get_results($sql,ARRAY_A); return $res; } /** *编码转换 * @param <type> $strInput * @return <type> */ function i($strInput) { return iconv('utf-8','gb2312',$strInput); } ?>
|
2022-08-30
2022-08-15
2022-08-17
2022-11-06
2022-08-17
请发表评论