Welcome Guest, Not a member yet? Register   Sign In
Stop Going To Funtion When Click Delete Files Button

(This post was last modified: 02-17-2017, 02:45 AM by wolfgang1983.)

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 }?>

Attached Files
.php   Newthread.php (Size: 5.63 KB / Downloads: 49)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!

(This post was last modified: 02-18-2017, 02:02 AM by Wouter60.)

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.

Theme © iAndrew 2016 - Forum software by © MyBB