我有几个文件保存在服务器上的文件夹和它们的路径存储在数据库中的表hwhic看起来像这样不能下载的文件保存在服务器上的文件夹中笨
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的文件应该得到下载并同样用第二和第三。
我使用的代码是下载文件,但是当我试图在我的系统上打开下载的文件时,它说文件没有正确下载。
查看
<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);
}
谁能告诉我怎么可以用笨
它应该是目录路径..不是** ** HTTP –
@MittulAtTechnoBrave你的意思是我应该只使用$ student_file? – user3732711
请查看https://www.codeigniter.com/userguide2/helpers/download_helper.html –