2011-03-14 160 views
0

这里是我的下载功能的代码片段。它会下载文件,但有时候我会尝试打开下载的文件,但我得到一个错误。它似乎文件已损坏..有人可以告诉我什么是错的代码?从数据库codeigniter下载文件

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

回答

1

检查$row[0]->type, $row->[0]->size, $row[0]->name(注释掉所有头()调用和转储$row),你allso不是测试,如果$query->result()返回一个有效的结果,allso检查是否有任何PHP警告或通知,allso检查如果有,你打电话之前header("Content-Type媒体链接发送给浏览器的所有头......

0

如果您确信您的要求得到且只有1个排,尽量选用:

$query->row(); 
在PLAC

e的

$query->result();