当前位置:网站首页>About CI framework batch export to compressed file
About CI framework batch export to compressed file
2022-06-11 10:21:00 【cathy1213】
Recently received a request , Many files need to be exported as compressed files , At first, I thought it was necessary to create directories layer by layer , Put the corresponding file in , Then use the compression class to compress the large folder as a whole , Later, it was found that it was not so complicated ,CI Of read_file Method to directly read the file into the specified location , then download After downloading, it is the hierarchy you want .
There is a problem after practice , Alibaba cloud oss Can't write directly to a compressed file , Maybe I can't read it , Because local files can be written directly . I can't find a solution online , Think about it. , Simply write the file locally first , Then write the compressed file locally , Here comes the question , frequently-used file_get_contents and file_put_contents There's no way oss Write the file locally , Maybe I'm not good at it , Use it in a different position curl Read , succeed , Problem solving . Here's how ... I didn't go into it , If there is a great God to help me answer the reason , Thank you very much .
$cur_encoding = iconv_get_encoding(); // Get current iconv The coding , Convenient for later conversion
$this->load->library('zip');
foreach ($attach_file as $v){
$extend2 = strtolower(strrchr($v['url'], '.')); // To obtain the suffix
//--------- Use curl Write files locally
$ch = curl_init($v['url']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata = curl_exec ($ch);
curl_close ($ch);
$fp = fopen(APPPATH.'cache/tmpdocx/a'.$extend2,'w'); //fopen The first parameter of , If you specify a directory , If the directory does not exist , Will not write successfully . You can also put it directly under the root directory , Anyway, this file is just a temporary file , It will still be deleted after the compressed file is written .
fwrite($fp, $rawdata);
fclose($fp);
//---------- Write completed .
$dir_name = $dir_title.'/ Mission statement /';
$dir_name = iconv ( $cur_encoding['input_encoding'], 'GBK', $dir_name); // Here is to ensure that the file name encoding supports Chinese , use iconv To GBK
$file_name = iconv($cur_encoding['input_encoding'],'GBK',$v['name']);
// use read_file Write compressed asking price , The first parameter is the use of curl Local file written , The second parameter is the target location , Support hierarchy , That is, the corresponding directory level in the compressed file .
$this->zip->read_file(APPPATH.'cache/tmpdocx/a'.$extend2,$dir_name.$file_name);
// Delete curl Temporary files generated .
unlink(APPPATH.'cache/tmpdocx/a'.$extend2);
}
// After all files are written to the compressed file , export , The browser will automatically download .
$this->zip->download(' Information .zip');
边栏推荐
- Use bat to write to the first line of the file
- Browser class for getting started with puppeter
- UGUI
- Some code fragments of a universal and confession wall system developed by PHP
- EMG线性光源发射器有哪些功能和特点呢?
- 手写代码call,apply,bind
- 以银行异业合作为例,浅谈小程序生态的建设
- Es6新特性——箭头函数
- Introduction to ZigBee module wireless transmission star topology networking structure
- DOtween使用方法
猜你喜欢

浅谈wandfluh比例阀的功能与作用

锐意进取,砥砺前行,JASMINER持续深耕品牌实力

What is the SOA or ASO of MOSFET?

How much do you know about the functions and functions of Rexroth solenoid directional valve

TikTok在英国遭遇文化冲突,短期内众多员工离职

With determination to forge ahead, JASMINER continues to deepen its brand strength

ZigBee模块通信协议的树形拓扑组网结构

EMG线性光源发射器有哪些功能和特点呢?

steamVR简介

Drink at night, 50 classic SQL questions, really fragrant~
随机推荐
Wsarecv: an existing connection was forcefully closed by the remote host
电子设备辐射EMC整改案例
UGUI
图表背后的秘密 | 技术指标讲解:唐奇安通道
DENISON液压泵用什么液压油?有哪些要求
B站到底能不能赚到钱?
Beginning simple blog emlog theme template V3
Cisp-pte XSS Foundation
Practical process of selecting DC-DC switching power supply controller
Some code fragments of a universal and confession wall system developed by PHP
宝塔面板备份与恢复数据
WordPress website backup
你对软件兼容性测试知道多少?如何选择软件兼容性测试机构?
How much do you know about software compatibility testing? How to select a software compatibility testing organization?
minIni移植到littlefs
Detailed explanation of Lora module wireless transceiver communication technology
【DBSCAN】DBSCAN实例
Wechat applet ordering system with source code
[Bert]: Calculation of last ave state when training tasks with similar Bert semantics
What are the functions and features of EMG linear light emitter?