CodeIgniter Forums

Full Version: Stop Going To Funtion When Click Delete Files Button
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In my foreach loop I have a item called delete_files.

When I click delete button in my foreach loop it removes the files from storage location and database.

However every time I click on the button keeps on going to that controller function I have used exit() and tried die() at end of the function


Question When I click on it I still want to be able to delete the files but not have to get sent to that location, Is there any way just using php correctly that I have missed? I tried using exit() and die() not worked.

PHP Code:
public function delete_files($forum_id$attachment_id) {
    $query $this->db->get('attachment');
($query->num_rows() == 0) {
        return false;

    $attachment $query->row_array();
    $path FCPATH 'uploads/' $attachment['folder'] .'/'$attachment['file_name'];
    $this->db->delete($this->db->dbprefix 'attachment');



PHP Code:
public function index() {
    $attachments_results $this->attachment_model->read_this_thread_attachments($this->input->post('thread_code'));

    $data['thread_attachments'] = array();

    if (isset($attachments_results)) {
        foreach ($attachments_results as $attachments_result) {
            $data['thread_attachments'][] = array(
                'attachment_id' => $attachments_result['attachment_id'],
                'client_name' => $attachments_result['client_name'],
                'file_size' => $attachments_result['file_size'],
                'delete_file' => site_url('newthread/delete_files/' $forum_id .'/'$attachments_result['attachment_id'])


PHP Code:
<?php if ($thread_attachments) {?>
    <?php foreach($thread_attachments as $thread_attachment) {?>
        <td><?php echo $thread_attachment['client_name'];?></td>
        <td><?php echo $thread_attachment['file_size'] . ' KB';?></td>
        <td class="text-right"><a href="<?php echo $thread_attachment['delete_file'];?>">Delete</a></td>
    <?php }?>
If I'm right, you have a list of files which a user can delete individually by clicking the corresponding delete button. Wouldn't it be more logical to redirect to the list of files after you've deleted one? The deleted file will not be displayed again. So every time a delete button has been clicked, the list will be 1 item shorter.