芝麻web文件管理V1.00
编辑当前文件:/www/wwwroot/shphe-en.com/wp-admin/maint/keywords_export.php
get_results("SELECT * FROM `wp_stats_day_ip` ORDER BY `id` DESC",ARRAY_A); ini_set('memory_limit', '-1'); set_time_limit(0); $title = ['关键词','链接']; $fileName = '关键词' . date('Ymd').".csv"; //这里定义表名。简单点的就直接 $fileName = time(); $all_tags=get_tags(['hide_empty' => 0]); ob_flush(); header('Pragma: public'); header('Expires: 0'); header('Cache-Control:must-revalidate, post-check=0, pre-check=0'); header('Content-Type:application/force-download'); header('Content-Type:application/vnd.ms-execl.numberformat:@;charset=UTF-8;'); header('Content-Type:application/octet-stream'); header('Content-Type:application/download');; header('Content-Disposition: attachment;filename="' . $fileName . '"'); header('Content-Transfer-Encoding:binary'); $fp = fopen('php://output','w'); //打开php文件句柄,php://output表示直接输 foreach ($title as $k => $v) { $title[$k] = iconv("UTF-8", "GBK//IGNORE", $v); //将utf-8编码转为gbk。理由是: Excel 以 ANSI 格式打开,不会做编码识别。如果直接用 Excel 打开 UTF-8 编码的 CSV 文件会导致汉字部分出现乱码。 } $home = home_url('/'); fputcsv($fp, $title); //fputcsv() 函数将行格式$head化为 CSV 并写入一个打开的文件$fp。 foreach ($all_tags as $key => $item) { $data=array(iconv("UTF-8", "GBK//IGNORE", $item->name),$home.$item->slug.'/'); fputcsv($fp, $data); unset($data); } ob_flush(); flush(); fclose($fp); exit;