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


$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);

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

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

和这个代码不工作PLZ发送我完整的代码与模型视图控制器。

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);
 }

控制器:

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

好的,兄弟,让我们来看看下面我的代码。

下面是我的代码: <<p> 视图/strong>
<a href="<?php echo base_url(')?>assets/save_files/$s->file_name">Download</a>

首先生成foreach()语句,foreach($result as $s)

:

$result你必须在你的控制器中创建一个函数:

控制器

public function get_all_data()
{
 $data['result'] = $this->model->get_data(); // 
$this->load->view('index',$data); //past the data to the view
}

public function get_data()
{
$query = $this->db->get('table_name');
return $query->result();
}

然后使用上面的锚代码下载保存文件的位置。

注意:

  • save_files为文件夹。
  • $ s→

最新更新