CodeIgniter的文件上传类允许文件被上传。您可以设置指定上传某类型的文件及指定大小的文件。
上传文件普遍的过程:
一个上传文件用的表单,允许用户选择一个文件并上传它。
当这个表单被提交,该文件被上传到指定的目录。
同时,该文件将被验证是否符合您设定的要求。
一旦文件上传成功,还要返回一个上传成功的确认窗口。
下面是表单:
复制代码 代码如下:<form method="post" action="<?=base_url()?>admin/img_upload/" enctype="multipart/form-data" />
<div style="margin:0 0 0.5em 0em;">
<input type="file" name="userfile" size="20" class="button" />
<input type="submit" value=" 上传 " class="button" />
</div>
</form>
然后是下面是上传类:
复制代码 代码如下:public function img_upload()
{
$this->load->helper('url');
$config['upload_path'] = './images/'.date('Ym', time()).'/';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = date('Y_m_d', time()).'_'.sprintf('%02d', rand(0,99));
$config['max_size'] = '500';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( !$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
}
}
需要用到的几个函数
$this->upload->do_upload():根据你的偏好配置参数执行操作。注意:默认情况下上传的文件来自于提交表单里名为userfile的文件域,并且该表单必须是 "multipart"类型。
$this->upload->display_errors():如果do_upload()返回失败,显示错误信息。此函数不会自动输出,而是返回数据,所以你可以按你的要求安排。
$this->upload->data():这是一个辅助函数,它返回你上传文件的所有相关信息的数组。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 金佩姗.1997-喜新恋旧【现代派】【WAV+CUE】
- 梁静茹.2007-崇拜【相信音乐】【WAV+CUE】
- 陈晓东.1997-在乎你感受(EP)【宝丽金】【WAV+CUE】
- 纯音入心系列纯音乐《云水禅心 - 佛曲古筝礼赞1-2》1CD[MP3][190MB]
- 纯音入心系列纯音乐《精心传神-古筝》1CD[MP3][363.1MB]
- 纯音入心系列纯音乐《琴瑟古风之古筝精选曲》1CD[MP3][354.1MB]
- 陈晓东.1997-在乎你感受(EP)【宝丽金】【WAV+CUE】
- 黄凯芹.1990-给你留念(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 张学友.1999-有个人【宝丽金】【WAV+CUE】
- 纯音入心系列纯音乐《古筝佛曲》1CD[MP3][411.1MB]
- 纯音入心系列纯音乐《古筝世界名曲》1CD[MP3][38.9MB]
- 纯音入心系列纯音乐《古筝新奏-菩提妙音》1CD[MP3][112.3MB]
- 陈思安.1993-怀念福建金曲5CD【歌丽美】【WAV+CUE】
- 张学友.1999-有个人【宝丽金】【WAV+CUE】