CI文件上传
哪位大神能帮我写一个demo啊 你用ajax插件还是? 就是form表单提交的 处理上传缩略图的方法,你看看CI的文档,说得很明白的!!{:1_1:}/**
* 处理上传的缩略图
* @access protected
* @param $field string //文件域name
* @return string
*/
protected function _upload_thumb($field)
{
#如果目录不存在,则尝试创建
if( !file_exists($this->_upload_floder))
{
mkdir($this->_upload_floder, 0777, TRUE);
}
#文件上传配置
$config['upload_path'] = $this->_upload_floder; //上传目录
$config['allowed_types'] = 'gif|png|jpg|jpeg'; //上传类型
$config['file_name'] = date('ymdhis').mt_rand(1000,9999); //按日期命名
$config['max_size'] = 200; //最大200KB
$this->load->library('upload',$config);
$thumb = '';
if( !empty($_FILES[$field]['tmp_name']) && $this->upload->do_upload($field))
{
$fileinfo = $this->upload->data();
$this->_thumb_config['origin_image'] = $fileinfo['full_path'];
$this->load->library('image_lib',$this->_thumb_config);
# 生成缩略图
if($this->image_lib->resize())
{
$thumb = $fileinfo['file_name'];
}
unset($fileinfo,$config);
}
return $thumb;
}
页:
[1]