原创jqueryForm实现上传
废话不说,上图function do_upload(){
$config['upload_path'] = './public/uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1024'; //kb
$config['max_width'] = '2048';
$config['max_height'] = '1536';
$config['encrypt_name'] = TRUE;
$this->load->library('upload',$config);
//var_dump($_FILES);
if(!$this->upload->do_upload()){
$data['info'] = $this->upload->display_errors();
header('Content-Type:text/html; charset=utf-8');
exit(json_encode($data));
//echo json_decode($data);
}else{
$upload_data=$this->upload->data();
header("Content-Type:text/html; charset=utf-8");
$data['status'] = 'success';
$data['info'] = '上传成功!';
$data['img'] = $upload_data['file_name'];
exit(json_encode($data));
}
}
<script type="text/javascript">
$(document).ready(function() {
$("#fileUp").ajaxForm({
success: complete,// post-submit callback
dataType: 'json'
})
function complete(data){
//alert(data);
if (data.status=='success'){
alert(data.info); //成功信息
$("#img",window.parent.document).html('<img src="<?php echo base_url()?>public/uploads/'+data.img+'"/>');
}else{
alert(data.info); //失败信息
}
}
});
</script>
HEX老大加分啊
页:
[1]