gpt4 book ai didi

javascript - 我如何在 Codeigniter 中处理 pdf 格式的文件下载?

转载 作者:行者123 更新时间:2023-11-28 17:51:00 26 4
gpt4 key购买 nike

我的要求是,我的 View 页面中有一个(下载)链接,当我单击该 View 页面时,我在注册期间已经上传的详细信息摘要必须以 pdf 格式下载。

最佳答案

According to doc

force_download([$filename = ''[, $data = ''[, $set_mime = FALSE]]])

Parameters:

  • $filename (string)
  • $data (mixed)
  • $set_mime (bool) – Whether to try to send the actual MIME type

Return type: void

Generates server headers which force data to be downloaded to yourdesktop. Useful with file downloads. The first parameter is the nameyou want the downloaded file to be named, the second parameter is thefile data.

If you set the second parameter to NULL and $filename is an existing,readable file path, then its content will be read instead.

If you set the third parameter to boolean TRUE, then the actual fileMIME type (based on the filename extension) will be sent, so that ifyour browser has a handler for that type - it can use it.

一般用法

    $this->load->helper('download');
force_download('/path/to/pdf.pdf', NULL);

具体情况的使用 - 放置在 Controller 中

function file_download()
{
$file_name= $this->input->get('file_name');

$this->load->helper('download');
$data = file_get_contents($file_name);
$name = 'My_new_name.pdf'; // custom file name for your download

force_download($name, $data);
//force_download($file_name, NULL); will get the file name for you
}

HTML假设您有这样的下载链接

<a class="downloadable" href="/Resumes/Resumes1271354404687.pdf">
/Resumes/Resumes1271354404687.pdf
</a>

Javascript

$(function(){
$('.downloadable').click(function(){

window.location.href = "<?php echo site_url('CONTROLLER_NAME/file_download') ?>?file_name="+ $(this).attr('href');
});
});

关于javascript - 我如何在 Codeigniter 中处理 pdf 格式的文件下载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45528650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com