Welcome Guest, Not a member yet? Register   Sign In
Download file only when click on link in foreach loop
#4

(This post was last modified: 02-13-2017, 12:02 PM by Wouter60.)

Why uri_segment()?
PHP Code:
public function downloads($id)
{

$this->db->where('attachment_id',$id);
$query $this->db->get('attachments');
If (
$query->num_rows() == 0) {
 
  Return false;
}

$attachment $query->row();
$path $attachment->path //assuming path end with a /
$file $attachment->file_name 

Force_download
($path $fileNULL);
}
//no exit needed 

In your view, replace the '<a>...</a>' part with:
PHP Code:
<?php echo anchor('preview/downloads/' $attachment['id'], $attachment['file_name');?>
Don't include the file name in the url. A file name may contain spaces or other characters that are not allowed in url's. Fetch the file name (and path) from the database.
The anchor helper function accepts 2 or 3 parameters.
1 = the link to the controller/method (the function will convert this the actual url)
2 = the text to click on (can be an image)
3 = string with additional attributes, like class, title, style etc.
Reply


Messages In This Thread
RE: Download file only when click on link in foreach loop - by Wouter60 - 02-13-2017, 10:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB