这是我现在正在做的事情:
$path = "./uploads/1.txt";
$path1 = "./uploads/4.txt";
$this->zip->read_file($path);
$this->zip->read_file($path1);
$this->zip->download('files_backup.zip');
现在我想从数据库查询中添加文件,返回文件的路径。
$data['query'] = $this->db->get_where('files', array('uid'=>$uid));
现在请告诉我,为了拨打$this->zip->read_file($path);
来自上述查询的结果..
感谢
修改
foreach ($query->result() as $row)
{
echo $row->filename;
}
结果
335476sfsr.txt
egyafhwe7g.txt
4566weyt36.txt
所以,它只显示该用户的文件..
答案 0 :(得分:8)
好的,那么就这样编辑给定的循环
foreach ($query->result() as $row)
{
$this->zip->read_file($row->filename);
}
$this->zip->download('files_backup.zip');
答案 1 :(得分:0)
使用表ITEMS创建数据库并添加IMG列,然后使用此代码。
查看:
<form method='post' action='<?= base_url() ?>index.php/zip/createzip/'>
<input type="submit" name="but_createzip1" value='Add file from path and download zip'>
</form>
控制器:
public function createzip(){
// Load zip library
$this->load->library('zip');
$query = $this->db->get('items');
foreach ($query->result() as $row)
{
$fileName = FCPATH."./uploads/".$row->img;
$this->zip->read_file($fileName);
}
$filename = "backup.zip";
$this->zip->download($filename);
}