将一个数组键/值将作为另一个数组的键/值
array_combine(array_values($row),$row)
峰扬
将一个数组键/值将作为另一个数组的键/值
array_combine(array_values($row),$row)
上代码
$base_str = "data:audio/mp3;base64,//...[这是一条很长的base64格式的字符串]";
if (preg_match('/^(data:\s*audio\/(\w+);base64,)/', $base_str, $result)){
$type = $result[2];//文件类型
$save_file = "./".date('Ymd',time())."/";//保存路径
if(!file_exists($save_file)){
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir($save_file, 0700);
}
$save_file = $new_file.time().".{$type}";
if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base_str)))){
dump($new_file);//结果
}else{
dump('失败');
}
}
先查找php-fpm.conf ,发现PHP的安装目录下没有该文件
在PHP安装目录下创建php-fpm配置文件,并输入以下内容(存在跳过此步骤)
[global]
pid = /www/server/php/70/var/run/php-fpm.pid
error_log = /www/logs/php/70/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi-70.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.status_path = /phpfpm_70_status
pm.max_children = 300
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 50
request_terminate_timeout = 100
request_slowlog_timeout = 30
slowlog = /www/logs/php/70/slow.log
找到apache的配置文件,找到 php_module 项(代表你的PHP版本号)注释该项
再找到 mod_proxy.so 和 mod_proxy_fcgi.so 以及 mod_rewrite.so项,解除注释,启用模块
在apache配置文件中加载其它配置(比如网站域名配置)
IncludeOptional /www/server/apache/vhost/*.conf
php-fpm模式5.png
创建测试文件
在web站点根目录下创建index.php
创建文件夹
mkdir /www/wwwroot/build
创建文件
vim /www/wwwroot/build/index.php
在文件中输入以下内容
phpinfo();
保存退出#
创建apache的虚拟主机站点配置文件
在IncludeOptional 项指定的目录下创建一个任意文件名.conf的配置,我这里是index.conf
vim /www/server/apache/vhost/index.conf
输入以下内容 (注意内容中的路径是可以自定义的)#
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot "/www/wwwroot/build" #这里指定web的根目录
ServerName 192.168.1.3 #这里是web网站访问的域名
ServerAlias 192.168.1.3 #这里也是web网站访问的域名
errorDocument 404 /404.html
ErrorLog "/www/logs/www/1.error_log" #这里是web网站访问的日志
CustomLog "/www/logs/www/1.access_log" combined #这里是web网站访问的错误日志
#DENY FILES
<Files ~ (\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)$>
Order allow,deny
Deny from all
</Files>
#PHP
<FilesMatch \.php$>
SetHandler "proxy:unix:/tmp/php-cgi-70.sock|fcgi://localhost"
</FilesMatch>
#PATH
<Directory "/www/wwwroot/build"> #这里指定web的根目录
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.php index.html index.htm default.php default.html default.htm
</Directory>
</VirtualHost>
修改所有新创建的文件所属权
重启apache
启动php-fpm
/www/server/php/56/sbin/php-fpm
/www/server/php/70/sbin/php-fpm
浏览器输入地址
访问成功
上代码
$objPHPExcel = new \PHPExcel();
// 设置表头 固定部分内容
$objPHPExcel->getActiveSheet()->mergeCells('A1:G1');//合并单元格 从A1到G1
$objPHPExcel->getActiveSheet()->setCellValue('A1',$fileName);//单元格内容
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setName('宋体');//A1单元格字体类型
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(17);//A1单元格字体大学
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);//A1单元格字体加粗
// 序号
$objPHPExcel->getActiveSheet()->mergeCells('A2:A3');//合并单元格 从A2到A3
$objPHPExcel->getActiveSheet()->setCellValue('A2','序号');//A2单元格内容
// 姓名
$objPHPExcel->getActiveSheet()->mergeCells('B2:B3');//合并单元格 从B2到B3
$objPHPExcel->getActiveSheet()->setCellValue('B2','姓名');//B2单元格内容
// 早餐
$objPHPExcel->getActiveSheet()->mergeCells('C2:D2');//合并单元格 从C2到D2
$objPHPExcel->getActiveSheet()->setCellValue('C2','早餐(8元/餐)');//C2单元格内容
$objPHPExcel->getActiveSheet()->setCellValue('C3','餐数');//C3单元格内容
$objPHPExcel->getActiveSheet()->setCellValue('D3','单位补助(4.8元/餐)');//D3单元格内容
// 午餐
$objPHPExcel->getActiveSheet()->mergeCells('E2:F2');
$objPHPExcel->getActiveSheet()->setCellValue('E2','午餐(14元/餐)');
$objPHPExcel->getActiveSheet()->setCellValue('E3','餐数');
$objPHPExcel->getActiveSheet()->setCellValue('F3','单位补助(8.4元/餐)');
//备注
$objPHPExcel->getActiveSheet()->mergeCells('G2:G3');
$objPHPExcel->getActiveSheet()->setCellValue('G2','备注');
//固定列
$start_row = 4;
foreach ($data['list'] as $key => $val) {
$objPHPExcel->getActiveSheet()->setCellValue('A'.$start_row,$key + 1);//No.
$objPHPExcel->getActiveSheet()->setCellValue('B'.$start_row,$val['name']);// 姓名
$objPHPExcel->getActiveSheet()->setCellValue('C'.$start_row,$val['breakfast']); // 早餐数
$objPHPExcel->getActiveSheet()->setCellValue('D'.$start_row,$val['breakfast_sum']); // 补助金额
$objPHPExcel->getActiveSheet()->getStyle('D'.$start_row)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$start_row,$val['lunch']); // 晚餐数
$objPHPExcel->getActiveSheet()->setCellValue('F'.$start_row,$val['lunch_sum']); // 补助金额
$objPHPExcel->getActiveSheet()->getStyle('F'.$start_row)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
$start_row ++;
}
// $start_row++;
$objPHPExcel->getActiveSheet()->mergeCells('A'.$start_row.':B'.$start_row);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$start_row,'合计');
$objPHPExcel->getActiveSheet()->setCellValue('C'.$start_row, '=SUM(C4:C'.($start_row-1).')');
$objPHPExcel->getActiveSheet()->setCellValue('D'.$start_row, '=SUM(D4:D'.($start_row-1).')');
$objPHPExcel->getActiveSheet()->setCellValue('E'.$start_row, '=SUM(E4:E'.($start_row-1).')');
$objPHPExcel->getActiveSheet()->setCellValue('F'.$start_row, '=SUM(F4:F'.($start_row-1).')');
$objPHPExcel->getActiveSheet()->getStyle('D'.$start_row)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
$objPHPExcel->getActiveSheet()->getStyle('F'.$start_row)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
//列+1
$start_row++;
$objPHPExcel->getActiveSheet()->mergeCells('A'.$start_row.':B'.$start_row);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$start_row,'总计');
$objPHPExcel->getActiveSheet()->mergeCells('C'.$start_row.':F'.$start_row);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$start_row, '=SUM(D'.($start_row-1).',F'.($start_row-1).')');
$objPHPExcel->getActiveSheet()->getStyle('C'.$start_row)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
$start_row++;
$objPHPExcel->getActiveSheet()->mergeCells('A'.$start_row.':B'.$start_row);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$start_row,'税额(8.5%)');
$objPHPExcel->getActiveSheet()->mergeCells('C'.$start_row.':F'.$start_row);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$start_row, '=C'.($start_row-1).'*0.085');
$objPHPExcel->getActiveSheet()->getStyle('C'.$start_row)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
$start_row++;
$objPHPExcel->getActiveSheet()->mergeCells('A'.$start_row.':B'.$start_row);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$start_row,'税后总计');
$objPHPExcel->getActiveSheet()->mergeCells('C'.$start_row.':F'.$start_row);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$start_row, '=SUM(C'.($start_row-2).':C'.($start_row-1).')');
$objPHPExcel->getActiveSheet()->getStyle('C'.$start_row)->getNumberFormat()->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
// 居中和水平居中
$objPHPExcel->getActiveSheet()->getStyle('A1:G'.$start_row)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('A1:G'.$start_row)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
// 设置边框
$objPHPExcel->getActiveSheet()->getStyle('A2:G'.$start_row)->getBorders()->getAllBorders()->setBorderStyle(\PHPExcel_Style_Border::BORDER_THIN);
// 落款
$start_row++;
$objPHPExcel->getActiveSheet()->setCellValue('A'.$start_row,'制表人:');
$objPHPExcel->getActiveSheet()->setCellValue('D'.$start_row,'审核人:');
$objPHPExcel->getActiveSheet()->getStyle('A2:G'.$start_row)->getFont()->setName('宋体');
$objPHPExcel->getActiveSheet()->getStyle('A2:G'.$start_row)->getFont()->setSize(12);
// 设置宽度
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(8);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(21);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(21);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(10);
$fileName = iconv("utf-8", "gb2312", $fileName.'.xls');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=\"$fileName\"");
header('Cache-Control: max-age=0');
//创建
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output'); //文件通过浏览器下载
exit;