+----------------------------------------------------------
下载文件
可以指定下载显示的文件名,并自动发送相应的Header信息
如果指定了content参数,则下载该参数的内容
+----------------------------------------------------------
public static download ( string $filename, string $showname = '', string $content = '', integer $expire = 180 ) | ||
$filename | string | 下载文件名 |
$showname | string | 下载显示的文件名 |
$content | string | 下载的内容 |
$expire | integer | 下载内容浏览器缓存时间 +---------------------------------------------------------- +---------------------------------------------------------- |
public function file_download() { $uploadpath = './Uploads/file/'; //设置文件上传路径,服务器上的绝对路径 $id = $_GET['id']; //GET方式传到此方法中的参数id,即文件在数据库里的保存id.根据之查找文件信息。 if ($id == '') { //如果id为空而出错时,程序跳转到项目的Index/index页面。或可做其他处理。 $this->display('没有找到该文件', U('Index/Index/index')); } $file = M('file'); //利用与表file对应的数据模型类FileModel来建立数据对象。 $result = $file->find($id); //根据id查询到文件信息 if ($result == false) { //如果查询不到文件信息而出错时,程序跳转到项目的Index/index页面。或可做其他处理 $this->display('没有找到该文件', U('Index/Index/index')); } $savename = $file->file_savename; //文件保存名 $showname = $file->file_truename; //文件原名 $filename = $uploadpath . $savename; //完整文件名(路径加名字) //print_r($filename);die; import('ORG.Net.Http'); Http::download($filename, $showname); }
function saveTickets($sql, $filename, $how = 'csv') { ob_start(); self::dumpTickets($sql, $how); $stuff = ob_get_contents(); ob_end_clean(); if ($stuff) { Http::download($filename, "text/{$how}", $stuff); } return false; }
public function download() { import('ORG.Net.Http'); header("Content-Type:text/html;charset=UTF-8"); $title = I('get.title'); $file_dir = './Public/upload/'; $Resource = D('Resource'); $map['id'] = I('get.id'); $list = $Resource->where($map)->order('id desc')->find(); $name = $list['content']; $filename = $file_dir . $name; $download = new Http(); $download->download($filename, $showtitle); }
public function download() { import("@.ORG.Http"); $id = $_GET['id']; $dao = M("Attach"); $attach = $dao->where("id=" . $id)->find(); $filename = $attach["savepath"] . $attach["savename"]; if (is_file($filename)) { if (!isset($_SESSION['attach_down_count_' . $id])) { $dao->setInc('downCount', "id=" . $id); $_SESSION['attach_down_count_' . $id] = true; } Http::download($filename, $attach->name); } }
protected function get_file($field, $error_empty = '', $error_unreachable = '') { if (empty($field)) { throw new Error_Api($error_empty, Error_Api::MISSING_INPUT); } if (strlen($field) < self::MAX_URL_LENGTH && parse_url($field)) { $data = Http::download($field); $error = $error_unreachable; } else { $data = base64_decode($field); $error = 'Некорректный формат передачи бинарных данных. Они были закодированы в base64?'; } if (empty($data)) { throw new Error_Api($error, Error_Api::INCORRECT_INPUT); } return $data; }
function index() { $aid = intval($_REQUEST['id']); $uid = intval($_REQUEST['uid']); $attach = D('Attach')->where("id='{$aid}' AND userId='{$uid}'")->find(); if (!$attach) { $this->error('附件不存在或已被删除!'); } //下载函数 import("ORG.Net.Http"); //调用下载类 if (file_exists(UPLOAD_PATH . $attach['savepath'] . $attach['savename'])) { $filename = iconv("utf-8", 'gb2312', $attach['savename']); Http::download(UPLOAD_PATH . $attach['savepath'] . $attach['savename'], $filename); } else { $this->error('附件不存在或已被删除!'); } }
public function download() { $aid = intval($_REQUEST['id']); $uid = intval($_REQUEST['uid']); $attach = model('Xattach')->where("id='{$aid}' AND uid='{$uid}'")->find(); //$attach = model('Xattach')->where("id='$aid'")->find(); if (!$attach) { $this->error('附件不存在或已被删除!'); } //下载函数 //import("ORG.Net.Http"); //调用下载类 require_cache('./addons/libs/Think/Http.class.php'); if (file_exists(UPLOAD_PATH . '/' . $attach['savepath'] . $attach['savename'])) { //增加下载次数 model('Xattach')->setInc('totaldowns', "id='{$aid}'"); //输出文件 $filename = $attach['name']; $filename = auto_charset($filename, "UTF-8", 'GBK'); //$filename = 'attach_'.$attach['id'].'.'.$attach['extension']; Http::download(UPLOAD_PATH . '/' . $attach['savepath'] . $attach['savename'], $filename); } else { $this->error('附件不存在或已被删除!'); } }
/** * 下载附件 * * @param int $aid 附件ID 为空时使用$_REQUEST['id']作为附件ID */ public function download($aid) { if (intval($aid) == 0) { $aid = intval($_REQUEST['id']); } $attach = M('Attach')->where("id='{$aid}'")->find(); if (!$attach) { $this->error('附件不存在或已被删除!'); } //下载函数 require_cache('./addons/libs/Think/Http.class.php'); if (file_exists(UPLOAD_PATH . $attach['savepath'] . $attach['savename'])) { $filename = iconv("utf-8", 'gb2312', $attach['savename']); Http::download(UPLOAD_PATH . $attach['savepath'] . $attach['savename'], $filename); } else { $this->error('附件不存在或已被删除!'); } }
public function log_export() { if (!IS_POST) { $this->message2('', '失败', 0); } $log_model = new Model('kongbao_order'); $userid = session('userid'); $where['user_id'] = $userid; $where['order_status'] = 1; $keyword = I('keyword', NULL); $ftype = I('ftype', NULL); if (!empty($keyword) && !empty($ftype)) { $where[$ftype] = array('like', '%' . $keyword . '%'); } $type_id = I('type_id', ''); if ($type_id != '') { $where['type_id'] = $type_id; } $log_list = $log_model->where($where)->order('order_time desc')->select(); $log_array = array(); $kb_type = M('kongbao_type')->select(); $type_array = array(); foreach ($kb_type as $type) { $type_array[$type['id']] = $type['name']; } $i = 0; foreach ($log_list as $k => $log) { $i++; $log_temp = array(); $log_temp[] = $i; $log_temp[] = $type_array[$log['type_id']]; $log_temp[] = $log['order_time']; $log_temp[] = $log['note_no']; $log_temp[] = $log['send_province'] . '-' . $log['send_city'] . '-' . $log['send_district']; $log_temp[] = $log['rec_province'] . '-' . $log['rec_city'] . '-' . $log['rec_district'] . $log['rec_address']; $log_temp[] = $log['rec_name']; $log_array[] = $log_temp; } $headers = array(array('序号', '快递类型', '下单时间', '单号', '发货地址', '收货地址', '收货人')); $order_counts = count($log_array); $file_name = $userid . '-' . $order_counts . '-' . time(); $fileurl = 'Public/Uploads/kb_log/' . $userid . '/'; MkdirAll($fileurl); $filename = $file_name . '.xls'; $fileurl = $fileurl . md5($file_name) . '.xls'; include 'Public/PHPExcel/PHPExcel.php'; include 'Public/PHPExcel/PHPExcel/Writer/Excel5.php'; include 'Public/PHPExcel/PHPExcel/Cell/DataType.php'; $m_objPHPExcel = new PHPExcel(); $this->write_xls($m_objPHPExcel, $fileurl, $headers, $log_array); import('ORG.Net.Http'); ob_end_clean(); $download = new Http(); $download->download($fileurl, $filename); exit; }
function downloadTabularData() { $data = $this->getData(); $csv = '"' . implode('","', $data['columns']) . '"'; foreach ($data['data'] as $row) { $csv .= "\n" . '"' . implode('","', $row) . '"'; } Http::download(sprintf('%s-report.csv', $this->get('group', __('Department'))), 'text/csv', $csv); }
/** * 下载附件 * * @param int $aid 附件ID 为空时使用$_REQUEST['id']作为附件ID */ public function download($aid) { if (intval($aid) == 0) { $aid = intval($_REQUEST['id']); } $attach = model('Attach')->field('savepath,savename,name')->where("id='{$aid}'")->find(); if (!$attach) { $this->error('附件不存在或已被删除!'); } //下载函数 require_cache('./addons/libs/Http.class.php'); $file_path = UPLOAD_PATH . '/' . $attach['savepath'] . $attach['savename']; if (file_exists($file_path)) { $filename = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? iconv('utf-8', 'gbk', $attach['name']) : preg_replace('/\\s/', '_', $attach['name']); Http::download($file_path, $filename); } else { $this->error('附件不存在或已被删除!'); } }
function download($disposition = false, $expires = false) { $disposition = $disposition ?: 'inline'; $bk = $this->open(); if ($bk->sendRedirectUrl($disposition)) { return; } $ttl = $expires ? $expires - Misc::gmtime() : false; $this->makeCacheable($ttl); Http::download($this->getName(), $this->getType() ?: 'application/octet-stream', null, $disposition); header('Content-Length: ' . $this->getSize()); $this->sendData(false); exit; }
/** * 导出SQL文件 * @access public * @return void */ public function outputData() { if (empty($_POST['table'])) { // 默认导出所有表 $tables = $this->db->getTables(Session('useDb')); } else { // 导出指定表 $tables = explode(',', $_POST['table']); } $this->db->execute('USE ' . Session('useDb')); // 组装导出SQL $sql = "-- ThinkPHP SQL Dump\n-- http://www.thinkphp.cn\n\n"; foreach ($tables as $key => $table) { $sql .= "-- \n-- 表的结构 `{$table}`\n-- \n"; $info = $this->db->query("SHOW CREATE TABLE {$table}"); $sql .= $info[0]['Create Table']; $sql .= ";\n-- \n-- 导出表中的数据 `{$table}`\n--\n"; $result = $this->db->query("SELECT * FROM {$table} "); foreach ($result as $key => $val) { foreach ($val as $k => $field) { if (is_string($field)) { $val[$k] = '\'' . $this->db->escapeString($field) . '\''; } elseif (empty($field)) { $val[$k] = 'NULL'; } } $sql .= "INSERT INTO `{$table}` VALUES (" . implode(',', $val) . ");\n"; } } $filename = empty($_POST['table']) ? Session('useDb') : $_POST['table']; import("ORG.Net.Http"); if (empty($_POST['zip'])) { file_put_contents(C('TEMP_PATH') . $filename . '.sql', trim($sql)); Http::download(C('TEMP_PATH') . $filename . '.sql'); } else { $zip = new \ZipArchive(); if ($zip->open(C('TEMP_PATH') . $filename . '.zip', \ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <{$filename}>\n"); } $zip->addFromString($filename . '.sql', trim($sql)); //$zip->addFile(TEMP_PATH.'thinkcms.sql',"ddd/test.sql"); $zip->close(); Http::download(C('TEMP_PATH') . $filename . '.zip'); } /* if(empty($_POST['zip'])) { import("ORG.Net.Http"); Http::download (TEMP_PATH.$filename.'.sql'); }else{ import('Think.Util.Archive'); $archive = new Archive($_POST['zip']); switch(strtolower($_POST['zip'])) { case 'gzip':$ext = '.tar.gz';break; case 'bzip':$ext = '.tar.bz2';break; case 'tar':$ext = '.tar';break; case 'zip': default:$ext = '.zip'; } $archive->add(TEMP_PATH.$filename.'.sql',$filename.'.sql',TRUE); $archive->download($filename.$ext); }*/ }
public function downfile() { $filename = I('file', ''); if ($filename == '') { $this->message2('无效请求!', U('database')); } $bkdir = 'Public/Uploads/backupdata'; $filepath = $bkdir . '/' . $filename; if (!file_exists($filepath)) { $this->message2('未找到备份文件!', U('database')); } $file_path = iconv('utf-8', 'gb2312', $filepath); import('ORG.Net.Http'); $download = new Http(); $download->download($file_path, $filename); }
public function download($file = null) { return Http::download('public/' . $file); }
/** * 下载文件 */ function down() { $filename = $_GET["file"]; $file_path = ROOT_PATH . './Backup/database/' . trim($filename, ".sql") . ".sql"; if (is_file($file_path)) { import('ORG.Net.Http'); $Http = new Http(); $Http->download($file_path, $filename . ".sql"); } else { $this->error("文件不存在或者已删除"); } }
/** * 文件下载 */ static function download($filename, $showname = '', $content = '', $expire = 180) { Yii::import('application.vendors.*'); require_once 'Tp/Http.class.php'; Http::download($filename, $showname, $content, $expire); }
function download() { $bk = $this->open(); if ($bk->sendRedirectUrl('inline')) { return; } $this->makeCacheable(); Http::download($this->getName(), $this->getType() ?: 'application/octet-stream', null, 'inline'); header('Content-Length: ' . $this->getSize()); $this->sendData(false); exit; }
/** * 下载 */ public function download() { $id = I('get.id'); $pic = $this->model->table('wechat_media')->field('file, file_name')->where('id = ' . $id)->find(); $filename = ROOT_PATH . $pic['file']; if (file_exists($filename)) { Http::download($filename, $pic['file_name']); } else { $this->message('文件不存在', NULL, 'error'); } }
static function saveOrganizations($sql, $filename, $how = 'csv') { $exclude = array('name'); $form = OrganizationForm::getDefaultForm(); $fields = $form->getExportableFields($exclude); // Field selection callback $fname = function ($f) { return 'cdata.`' . $f->getSelectName() . '` AS __field_' . $f->get('id'); }; $sql = substr_replace($sql, ',' . implode(',', array_map($fname, $fields)) . ' ', strpos($sql, 'FROM '), 0); $sql = substr_replace($sql, 'LEFT JOIN (' . $form->getCrossTabQuery($form->type, '_org_id', $exclude) . ') cdata ON (cdata._org_id = org.id) ', strpos($sql, 'WHERE '), 0); $cdata = array_combine(array_keys($fields), array_values(array_map(function ($f) { return $f->get('label'); }, $fields))); $cdata += array('account_manager' => 'Account Manager', 'users' => 'Users'); ob_start(); echo self::dumpQuery($sql, array('name' => 'Name') + $cdata, $how, array('modify' => function (&$record, $keys) use($fields) { foreach ($fields as $k => $f) { if ($f && ($i = array_search($k, $keys)) !== false) { $record[$i] = $f->export($f->to_php($record[$i])); } } return $record; })); $stuff = ob_get_contents(); ob_end_clean(); if ($stuff) { Http::download($filename, "text/{$how}", $stuff); } return false; }
public function download() { $aid = intval($_REQUEST['id']); $uid = intval($_REQUEST['uid']); $attach = model('Attach')->where("id={$aid} AND userId={$uid}")->find(); //$attach = model('Xattach')->where("id='$aid'")->find(); if (!$attach) { $this->error(L('attach_noexist')); } //下载函数 require_cache('./addons/libs/Http.class.php'); $file_path = UPLOAD_PATH . '/' . $attach['savepath'] . $attach['savename']; if (file_exists($file_path)) { $filename = iconv("utf-8", 'gb2312', $attach['name']); Http::download($file_path, $filename); } else { $this->error(L('attach_noexist')); } }
function zip() { $database_path = Tiny::getPath('database'); $backs = Req::args("back"); if (!empty($backs)) { if (is_array($backs)) { $len = count($backs); for ($i = 0; $i < $len; $i++) { $backs[$i] = $database_path . $backs[$i]; } } if (file_exists($database_path . "sql.zip")) { unlink($database_path . "sql.zip"); } Http::zip($backs, $database_path . "sql.zip"); Http::download($database_path . "sql.zip", date('YmdH') . '_' . rand(1000, 9999) . ".zip"); } else { $this->msg = array("warning", '必需选择文件,才能进行打包下载!'); $this->redirect("back_list", false); } }
public function down_daili() { $id = I('id', NULL); $userid = session('userid'); $where['id'] = $id; $where['user_id'] = $userid; $uploadfile = M('uploadfiles')->where($where)->find(); if (!empty($uploadfile) && $uploadfile['fileurl'] != '') { $file_path = $uploadfile['fileurl']; $file_name = $uploadfile['filename'] . '.xls'; } else { $this->message2('文件不存在', 'daili_upload'); } $file_path = iconv('utf-8', 'gb2312', $file_path); import('ORG.Net.Http'); ob_end_clean(); $download = new Http(); $file_name = urldecode($file_name); $download->download($file_path, $file_name); }
/** * [download 下载文件] * @param string $url [文件地址] * @param string $filename [显示名称] * @return [type] [description] */ function download($url = '', $filename = '') { import("ORG.Net.Http"); $url = !empty($url) ? $url : './Data/dirty_words_formart_config.xml'; Http::download($url, $filename); }
/** +---------------------------------------------------------- * 导出SQL文件 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @return void +---------------------------------------------------------- */ public function outputData() { @set_time_limit(300); $filename = empty($_POST['tableName']) ? $this->dbName : (count($_POST['tableName']) > 1 ? str_replace('.', '_', $_SERVER['HTTP_HOST']) . '_tables' : implode(',', $_POST['tableName'])); $filepath = TEMP_PATH . $filename . '.sql'; if (file_exists("{$filepath}")) { unlink("{$filepath}"); } $filepath = TEMP_PATH . $filename . '.zip'; if (file_exists("{$filepath}")) { unlink("{$filepath}"); } import("ORG.Net.Http"); if (empty($_POST['tableName'])) { // 默认导出所有表 $tables = $this->db->getTables($this->dbName); } else { // 导出指定表 $tables = $_POST['tableName']; } $this->db->execute('USE ' . $this->dbName); // 组装导出SQL foreach ($tables as $key => $table) { $sql .= "-- \n-- 表的结构 `{$table}`\n-- \n"; $info = $this->db->query("SHOW CREATE TABLE {$table}"); $sql .= $info[0]['Create Table']; $sql .= ";\n-- \n-- 导出表中的数据 `{$table}`\n--\n"; $count = $this->db->query("SELECT count(*) as num FROM {$table} "); $tanumpro = $count[0][num]; if ($tanumpro > 5000) { for ($i = 0; $i <= $tanumpro;) { $result = $this->db->query("SELECT * FROM {$table} limit {$i},5000"); foreach ($result as $key => $val) { foreach ($val as $k => $field) { if (is_string($field)) { $val[$k] = '\'' . $this->db->escape_string($field) . '\''; } elseif (empty($field)) { $val[$k] = 'NULL'; } } $sql .= "INSERT INTO `{$table}` VALUES (" . implode(',', $val) . ");\n"; } $i = $i + 5000; $fp = fopen(TEMP_PATH . $filename . '.sql', "a+"); fwrite($fp, $sql); fclose($fp); $sql = ''; } } else { $result = $this->db->query("SELECT * FROM {$table} "); foreach ($result as $key => $val) { foreach ($val as $k => $field) { if (is_string($field)) { $val[$k] = '\'' . $this->db->escape_string($field) . '\''; } elseif (empty($field)) { $val[$k] = 'NULL'; } } $sql .= "INSERT INTO `{$table}` VALUES (" . implode(',', $val) . ");\n"; } $fp = fopen(TEMP_PATH . $filename . '.sql', "a+"); fwrite($fp, $sql); fclose($fp); $sql = ''; } } if (empty($_POST['zip'])) { //file_put_contents(TEMP_PATH.$filename.'.sql',trim($sql)); Http::download(TEMP_PATH . $filename . '.sql'); } else { /*echo TEMP_PATH.$filename.'.zip'; echo $filename.'.sql'; exit;*/ $zip = new ZipArchive(); if ($zip->open(TEMP_PATH . $filename . '.zip', ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <{$filename}>\n"); } // $zip->addFromString($filename.'.sql',trim($sql)); $zip->addFile(TEMP_PATH . $filename . '.sql', $filename . '.sql'); $zip->close(); Http::download(TEMP_PATH . $filename . '.zip'); } }
public function downfile() { $id = I('id', ''); if ($id == '') { $this->message2('未指定下载项!', U('order_exp_new')); } $file = M('exp_log')->where('id=' . $id)->find(); if (empty($file)) { $this->message2('指定下载项不存在!', U('order_exp_new')); } $fileurl = $file['exp_fileurl']; $filename = $file['exp_filename']; if ($fileurl == '') { $this->message2('无效请求!', U('order_exp_new')); } $filepath = $fileurl; if (!file_exists($filepath)) { $this->message2('未找到对应的导出文件!', U('order_exp_new')); } $file_path = $filepath; import('ORG.Net.Http'); ob_end_clean(); $download = new Http(); $download->download($file_path, $filename); }
public function doDownload() { $filename = basename($_REQUEST['filename']); // 下载函数 require_once ADDON_PATH . '/library/Http.class.php'; $file_path = DATA_PATH . '/database' . '/' . $filename; if (file_exists($file_path)) { $filename = iconv("utf-8", 'gb2312', $filename); Http::download($file_path, $filename); } else { $this->error("数据不存在!"); } }
protected function get_html($id) { $updated = Database::get_field('board', 'updated', '`type` != ? and id = ?', array('deleted', $id)); if (!empty($updated)) { $file_name = 'thread_'.$id.'_'.$updated.'.html'; if (!file_exists(self::$work_dir.$file_name)) { $css = file_get_contents(ROOT_DIR.SL.'jss'.SL.'main.css'); $css_regex = '/^\/\*.+?\*\/(.*?)\/\*.*\/\*\s+Content,\s+борда\s+\*\/(.*?)\/\*/uis'; preg_match($css_regex, $css, $css); $style = '<style>'.$css[1].$css[2].'</style>'; $encoding = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; $head = '<head>'.$encoding.$style.'</head>'; $download_url = 'http://'.def::site('domain'). '/board/download/thread/'.$id; $body = '<body>'.Http::download($download_url).'</body>'; $body = preg_replace_callback('/<img[^>]+>/si', array('self', 'image_encode'), $body); $file = fopen(self::$work_dir.$file_name,'w'); fwrite($file,preg_replace('/[\n\r\t]+/','','<html>'.$head.$body.'</html>')); fclose($file); } return self::$work_dir.$file_name; } return false; }
/** * 附件下载 */ public function down() { $aid = intval($_GET['attach_id']); $attach = model('Attach')->getAttachById($aid); if (!$attach) { die(L('PUBLIC_ATTACH_ISNULL')); } $filename = $attach['save_path'] . $attach['save_name']; $realname = auto_charset($attach['name'], "UTF-8", 'GBK//IGNORE'); //下载函数 tsload(ADDON_PATH . '/library/Http.class.php'); //从云端下载 $cloud = model('CloudAttach'); if ($cloud->isOpen()) { $url = $cloud->getFileUrl($filename); redirect($url); //$content = $cloud->getFileContent($filename); //读文件下载 //Http::download('', $realname, $content); //从本地下载 } else { if (file_exists(UPLOAD_PATH . '/' . $filename)) { Http::download(UPLOAD_PATH . '/' . $filename, $realname); } else { echo L('PUBLIC_ATTACH_ISNULL'); } } }
function exportcsv() { $csvfile = TEMP_PATH . "products.csv"; self::$Model = D('Products'); if (isset($_POST['cateid']) && !empty($_POST['cateid'])) { $cateid = D('Cate')->getChildren($_POST['cateid'], $_POST['cateid']); $map['cateid'] = array('in', $cateid); $list = self::$Model->where($map)->select(); } else { $list = self::$Model->select(); } if ($list) { $fields = self::$Model->query("SHOW COLUMNS FROM __TABLE__"); $dbfields = array(); //位置 foreach ($fields as $field) { $dbfields[] = $field['Field']; } $file = fopen($csvfile, "w+"); //翻译 $lang = array('id' => '产品id', 'cateid' => '类别id', 'name' => '产品名称', 'serial' => '产品货号', 'price' => '市场价格', 'pricespe' => '商店价格', 'weight' => '重量', 'bigimage' => '原图', 'smallimage' => '缩略图', 'remark' => '产品描述', 'isnew' => '是否新产品', 'ishot' => '是否热门产品', 'isrec' => '是否推荐产品', 'isprice' => '是否特价产品', 'isdown' => '是否下架产品', 'dateline' => '添加时间', 'sort' => '排序', 'brandid' => '品牌id', 'viewcount' => '点击数', 'points' => '积分', 'costprice' => '成本价', 'provider' => '供应商', 'stock' => '库存', 'pagetitle' => 'meta标题', 'pagekey' => 'meta关键字', 'pagedec' => 'meta描述'); //标题 $title = array(); foreach ($dbfields as $key => $val) { $title[] = $lang[$val] ? $lang[$val] : $val; } fputcsv($file, auto_charset($title, 'utf-8', 'gbk')); //内容 foreach ($list as $line) { fputcsv($file, auto_charset($line, 'utf-8', 'gbk')); } fclose($file); import("ORG.Net.Http"); Http::download($csvfile); } else { $this->error('没有产品数据'); } }