Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
wp-admin
/
js
:
keywords_export.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php define( 'SITE_URL', $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'] ); define( 'DOING_AJAX', true ); define( 'WP_ADMIN', true ); /** Load WordPress Bootstrap */ require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' ); /** Allow for cross-domain requests (from the frontend). */ send_origin_headers(); /** Load WordPress Administration APIs */ require_once( ABSPATH . 'wp-admin/includes/admin.php' ); /** Load Ajax Handlers for WordPress Core */ require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' ); @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); @header( 'X-Robots-Tag: noindex' ); send_nosniff_header(); nocache_headers(); do_action( 'admin_init' ); if ( !is_user_logged_in() ){ header('location:/admin.php'); } global $wpdb; $list = $wpdb->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;