AVRIL_START_JANCOKALIVEAVRIL_END_JANCOK
| Server IP : dzynews.com / Your IP : 216.73.217.105 Web Server : nginx/1.30.3 System : Linux cloud-tdkldl-avd6 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 User : www ( 1000) PHP Version : 8.2.31 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/dzynews.com/wp-content/themes/archive-document/Modules/Settings/ |
Upload File : |
<?php
namespace B2\Modules\Settings;
class Array2Csv{
public $_useGbk = true;
private $fp = null;
public function __construct(){
//打开PHP文件句柄,php://output 表示直接输出到php缓存
ob_end_clean();
$this->fp = fopen('php://output', 'w');
}
//设置头部
public function cvsHeader($filename)
{
//error_reporting(0);
if($this->_useGbk) {
header("Content-type:text/csv;charset=gbk");
} else {
header("Content-type:text/csv;charset=utf-8");
}
header("Content-Disposition:attachment;filename=" . $filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0,max-age=0');
header('Expires:0');
header('Pragma:public');
}
//采用putcsv封装格式
public function outputData($data){
foreach ($data as $key => $value) {
//CSV的Excel支持GBK编码,一定要转换,否则乱码
$data[$key] = iconv('utf-8', 'gbk', $value);
// $data[$key] = $value;
}
fputcsv($this->fp,$data);
}
//刷新缓存,将PHP的输出缓存输出到浏览器上
public function csvFlush(&$cnt){
ob_flush();
flush();
}
//关闭输出流
public function closeFile(){
fclose($this->fp);
}
}