【发布时间】:2016-11-18 12:29:29
【问题描述】:
我在服务器文件夹中保存的文件很少,它们的路径存储在数据库表中,看起来像这样
Table Name: student_file
id name file
1 abc asd/fgh/abc.docx
2 def asd/fgh/def.pdf
3 ghi asd/fgh/ghi.doc
我已从上表(student_file)中提取数据并以表格形式显示,其中“下载”将是一个链接或按钮,如下所示
abc download
def download
ghi download
现在我希望如果用户单击第一次下载,那么 abc 的文件应该被下载,并且与第 2 和第 3 相同。
我使用的代码正在下载文件,但是当我试图在我的系统上打开下载的文件时,它说文件没有正确下载。
查看
<a href="<?php echo base_url()?>admin/download/1">Download</a>
控制器
public function download($id)
{
$data['download'] = $this->admin_model->get_download_data($id);
}
型号
public function get_download_data($id)
{
$this->db->where('id',$id);
$data = $this->db->get('student_file');
$student_data = $data->row();
$student_file = $student_data->file;
$ext = substr($student_file, strpos($student_file, ".") + 1);
$path = 'www.xyz.com/';
$file = $path . $student_file;
header("Content-type:application.$ext");
header("Content-Disposition:attachment;filename='downloaded.$ext");
readfile($file);
}
谁能告诉我如何使用codeigniter正确下载这些文件
【问题讨论】:
-
它应该是目录路径..不是http
-
@MittulAtTechnoBrave 你的意思是我应该只使用 $student_file ?
标签: php codeigniter download codeigniter-2 codeigniter-3