文件上传+验证码

文件上传:

$config['upload_path'] = './public/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload',$config);
$this->upload->do_upload('u_file');
$info = $this->upload->data();
$data['u_file'] = $info['file_name'];
$flag = $this->db->insert("zhou1",$data);

<td><img id='pic' src="<?php echo base_url('public/uploads').'/'.$val['u_file']?>" alt="加载失败" width=50px; height=50px;/></td>

//图片放大放小
$('#pic').click(function(){
var size=parseInt($(this).attr('width'))+20;
var height=parseInt($(this).attr('height'))+20;
$(this).attr('width',size);
$(this).attr('height',height);
})

//缩略图

//图片处理,上传图片
$config['upload_path'] = './Public/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if($this->upload->do_upload('img')){
$info=$this->upload->data();
//var_dump($info);exit;
//以原图来生成缩略图
$config1['source_image'] = './Public/uploads/'.$info['file_name'];
$config1['create_thumb'] = TRUE;
$config1['maintain_ratio'] = TRUE;
$config1['width'] = 75;
$config1['height'] = 50;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
//原图
$data['goods_img']=$info['file_name'];
//缩略图
$data['goods_thumb']=$info['raw_name'].'_thumb'.$info['file_ext'];
//接收数据
$data['goods_sn']=$this->input->post('goods_sn');
$data['goods_name']=$this->input->post('goods_name');
.
.
.
}

//接受原文件图片
$config['upload_path'] = './Public/uploads/thumb/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200000';
//初始化
$this->upload->initialize($config);
if($this->upload->do_upload('g_img')){
$info=$this->upload->data();
$config['source_image'] = './Public/uploads/thumb/'.$info['file_name'];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;
$this->image_lib->initialize($config);
$thumb=$this->image_lib->resize();
$goods=array();
$attr=array();
$goods['g_img']=$info['file_name'];
$goods['g_thumb']=$info['raw_name'].'_thumb'.$info['file_ext'];

验证码:

header("content-type:image/jpeg");
imagejpeg($im);
ImageDestroy($im);
return $word;

<tr>
<td><input type="text" id="codes" placeholder="请输入验证码"/></td>
<td><img src="<?php echo site_url('Welcome/check_code')?>" οnclick=this.src="<?php echo site_url('Welcome/check_code').'/'?>"+Math.random()></td>
</tr>

//验证码
public function check_code(){
$code = create_captcha();
$this->session->set_userdata('code',$code);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值