codeigniter - 从数据库下载文件或在 codeigniter 中保存文件夹

$data = 'Here is some text!';
$name = 'mytext.txt';

force_download($name, $data);

这是我需要从数据库或我的保存路径文件夹下载的简单 bownload 代码位。

我需要MVC codeigniter框架中的完整代码。
我在数据库和给定路径文件夹中上传文件 我制作了我最终学位的在线工作门户项目 我想下载简历或文件,但我不能下载它请帮助我。我如何从数据库或保存文件夹。

此代码无法正常工作,请将带有 Model View Controller 的完整代码发送给我。

function download($fid){
    $query= $this->db->get_where('files',array('fid' => $fid));

$row = $query->result();
header("Content-Type: ". $row[0]->type);
header("Content-Length: ". $row[0]->size);
header("Content-Disposition: attachment; filename=". $row[0]->name);

// Print data
echo $row[0]->content;

//Free the mysql resources
mysql_free_result($result);
//redirect('index.php/files/search/'.$fid);
 }

最佳答案

Controller :

public function download($file)
{

$this->load->helper('download');
$name = $file;
$data = file_get_contents('./uploads/foldername/'.$file); 
force_download($name, $data); 
    redirect('index','refresh');
}

https://stackoverflow.com/questions/33220652/

相关文章:

html - HTML LocalStorage 中的数据在其他窗口/选项卡中可用所需的时间

laravel - 如何在 Laravel 的容器中重新绑定(bind)?

android - 将抽屉导航添加到现有的 Android 谷歌地图

angularjs - 如何使用 Firebase 和 AngularJS 创建评论线程?

c++11 - 将 char16_t 转换为 long/integer,(相当于 atoi/atol

iis - 如何在没有收到确认消息的情况下退出 IIS Express 工作进程?

gstreamer - 使用 Gstreamer 编码/解码 VP8 或 VP9?

session - 身份验证为匿名的用户已尝试访问拥有的 session

jboss - Keycloak 自定义验证输出消息

maven - 在 Nexus 中部署后,POM.xml 中的变量没有被解析?