2013-07-09 28 views
1

我想从我的数据库中删除和下载上传文件 我已经上传并显示它现在我想下载并删除文件iupload 这是我的控制器showupload.php如何在codeigniter中下载和删除文件

<?php class Showupload extends CI_Controller { 

function __construct() 
{ 
    parent::__construct(); 
    $this->load->helper(array('form', 'url')); 
} 

function index() 
{ 

    $this->load->model('showuploadmodel'); 
    $data['query']=$this->showuploadmodel->showfile(); 
    $this->load->view('showupload_view',$data); 


} 
public function delete_upload($file_id) { 
    $this->load->showupload('showuploadmodel'); 
    $data = $this->showuploadmodel->delete($file_id); 
    $this->load->view('showupload_view',$data); 
} 
public function download($filelink) 
{ 
$this->load->helper('download'); 
$data = file_get_contents("$filelink"); // Read the file's link 
force_download($filelink, $data);    
} 
} 
?> 

,这是我的看法show_upload_view.php

<?php include_once('header.php'); ?> 
<?php include_once('tnavbar.php'); ?> 

<html> 
<head> 
<title>Show Upload</title> 
</head> 
<body> 


<div class='well'> 
<table border="0"> 
    <tr> 
    <th><h1>File Name</h1></th> 
    <th><h1>Date</h1></th> 
    <th><h1>Action</h1></th> 
    </tr> 
<?php 
foreach($query as $row){ 
echo "<tr>"; 
echo "<td><h2>". $row->filename ."</h2></td>"; 
    echo "<td><h2>". $row->date ."</h2></td>"; 
    echo "<td><h2>".Download|Delete."</h2></td>"; 
    //now how can i make download and delete from my database 
    //my database contains filename,fileid,filelink  
    echo "</tr>"; 
} 
?> 
</table> 

</div> 

</body> 
</html> 

现在我怎么可以让下载和从我的数据库中删除 我的数据库中包含文件名,的fileid,filelink

+0

如何在ab中添加下载助手和文件助手utton ???????? – nadimsajib

回答

0

如需下载,你应该使用下载助手

http://ellislab.com/codeigniter/user-guide/helpers/download_helper.html

$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents 
$name = 'myphoto.jpg'; 

force_download($name, $data); 

并删除你在文件助手删除功能

http://ellislab.com/codeigniter/user-guide/helpers/file_helper.html

delete_files('./path/to/directory/'); 
+0

但我如何将这添加到按钮或链接??????请帮助我在codeigniter新 – nadimsajib