• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Download file only when click on link in foreach loop

#4
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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.