codeigniter download problem
when using download helper in Ci, I get file download pop up as开发者_Go百科 page load , how do i stop that ?
working as intended, if you want to stop it, stop using the download helper.
the download helper sends the appropriate headers so that the file is forced to download to the users desktop/downloads
what are you trying to do ?
edit Ok so say your controller is called "download" and your method is called "view" which displays links to your downloads like this:
mysite.com/download/process/foo.pdf
create a method in your download
controller called process
function process($file)
{
$this->load->helper('download');
$data = file_get_contents("my-downloads/$file"); // Read the file's contents
force_download($file, $data);
}
untested but it should work
you will want some validation etc.
so the user views the downloadable files on downloads/view
and when they click a link, they go to the process
method to download the file.
you will probably want a redirect or similar after the file download starts, and i expect you could do it with AJAX so the user never leaves the page.
Try this:
function do_download($file_name="")
{
$file_path = 'custom/uploads/project/'.$file_name;
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=$file_name");
ob_clean();
flush();
readfile($file_path);
}
精彩评论