codecamp

CodeIgniter 下载辅助函数

下载辅助函数

下载辅助函数文件包含了下载相关的一些函数。

加载辅助函数

该辅助函数通过下面的代码加载:

$this->load->helper('download');

可用函数

该辅助函数有下列可用函数:

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

参数:

  • $filename (string) -- Filename
  • $data (mixed) -- File contents
  • $set_mime (bool) -- Whether to try to send the actual MIME type

返回类型: void

生成 HTTP 头强制下载数据到客户端,这在实现文件下载时很有用。 第一个参数为下载文件名称,第二个参数为文件数据。

如果第二个参数为空,并且 $filename 参数是一个存在并可读的文件路径, 那么这个文件的内容将被下载。

如果第三个参数设置为 TRUE,那么将发送文件实际的 MIME 类型(根据文件的扩展名), 这样你的浏览器会根据该 MIME 类型来处理。

Example:

$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);

下载一个服务器上已存在的文件的例子如下:

// Contents of photo.jpg will be automatically read
force_download('/path/to/photo.jpg', NULL);
CodeIgniter 目录辅助函数
CodeIgniter 邮件辅助函数
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }