某些pdf文件位于我的文件夹中,并带有用户ID。每当用户选择前端的行时,特定记录是否存在检查并生成zip文件并下载。但我想用用户名替换pdf文件名?
例如在我的文件夹101.pdf存储时,我生成zip 101更改用户名smith.pdf文件生成zip并下载?怎么样?
public function download_pdf()
{
$createdzipname = 'reportszip';
$this->load->library('zip');
$this->load->helper('download');
$this->zip->add_dir('zipfolder');
$userIds=$this->input->post('user_ids');//userids are like 101,102,103
$file_names=explode(',',$userIds);
$files = $file_names;
$i=0;
foreach($files as $file)
{
$reportfile=$file;
$s1=strlen($reportfile);
$s2=9;
$s3=$s2-$s1;
$string_before=str_pad($value, $s3, '0', STR_PAD_LEFT);
$fileename=$string_before.$reportfile;
$paths = base_url().'report/pdf/'.$fileename.'.pdf';
$this->zip->add_data('zipfolder/'.$paths,file_get_contents($paths));
$i++;
}
$this->zip->download($createdzipname.'.zip');
}