public function file_down()
{
$this->load->helper('download');
$this->load->model('files_model');
$filename = $this->uri->segment(3,0);
$fname = $this->files_model->download_files($filename);
force_download($fname, $filename);
//print_r($fname);
//echo $filename;
}
윗 부분은 Controller
public function download_files($filename)
{
return $fname = $this->db->select()
->from('files')
->where('title = "'.$filename.'" ')
->get()
->result();
// print_r($fname);
}
윗 부분은 Model
<?php
if (isset($files) && count($files))
{
?>
<ul>
<?php
foreach ($files as $file)
{
?>
<li class="image_wrap">
<a href="#" class="delete_file_link" data-file_id="<?php echo $file->id?>">Delete</a>
<strong><?php echo $file->title?></strong>
<br />
<a href="/upload/file_down/<?=$file->title?>"><?php echo $file->filename?></a>
</li>
<?php
}
?>
</ul>
</form>
<?php
}
view부분입니다.
해외 사이트 참고하여 upload부분까지는 됐는데요
테이블에 id값이 있지만 일단 데이터 하나만 넣어서 이름으로 다운로드가 되는지 테스트해보고있었는데요
download는 제가 생각한대로 추가한겁니다.
db에서 가져올때 저렇게 가져올려고하니
Message: Array to string conversion
Filename: helpers/download_helper.php에러가 나더라구여
그래서 $fname을 implode해서 title만뽑으려고 echo를했는데
Object of class stdClass could not be converted to string에러가 뜨던데 오브젝트클래스는 무슨 스트링형으로 변환할수없다?이건거같은데 어떻게 해결해야하나여??
public function download_files($filename)
{
return $fname = $this->db->select()
->from('files')
->where('title = "'.$filename.'" ')
->get()
->result();
// print_r($fname);
}
모델에서 반환된 $fname을 print_r로 찍어보세요