2012-03-20 85 views
0

控制器方法我有一个方法在我的控制器调用从视图

public function download($filepath){ 

$download_path = $_SERVER['DOCUMENT_ROOT']. "mediabox/import"; 
$file = $download_path + $filepath ; 

if(!$file) die("I'm sorry, you must specify a file name to download."); 
if(eregi("\.ht.+", $file)) die("I'm sorry, you may not download that file."); 
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist."); 
$type = filetype($file); 

    header("Content-type: $type"); 
header("Content-Disposition: attachment;filename=$filename"); 
header('Pragma: no-cache'); 
header('Expires: 0'); 
    // Send the file contents. 
readfile($file); 

} 

在我看来,我有一个链接

<a target='_blank' class='download_dialog' onClick="???"> 

我想打电话给我的控制器onclick事件的下载实现方法具链接 。 这样做好吗? 我该怎么办? 感谢

回答

1

你可以尝试:

<a target='_blank' class='download_dialog' href="<?php echo base_url();?>YourControllerName/download"> 

(是的,你需要使用要base_url的url助手)或在某些javascript onClick调用中使用该url,但我不确定这是否是最适合您的解决方案。

+0

如果有什么方法是在我的模型? – 2012-03-20 15:43:31

+0

感谢它工作:) – 2012-03-20 15:48:32