gpt4 book ai didi

database - 上传带有图像的数据在 codeigniter 中不起作用

转载 作者:搜寻专家 更新时间:2023-10-30 22:59:57 25 4
gpt4 key购买 nike

我目前正在制作一个模块,用户可以在其中将包含一些详细信息的图像上传到数据库,但它不起作用,甚至验证都没有显示我已经为图像创建了上传目录

Controller :

public function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['max_height'] = '1024';
$config['new_image'] = './uploads/';

$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
$this->form_validation->set_rules('type', 'Type', 'required');
$this->form_validation->set_rules('school', 'School', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if (!$this->upload->do_upload() || !$this->form_validation->run()) {
$error = array('error' => $this->upload->display_errors());
redirect('user/payment');
} else {
$data = $this->upload->data();
$this->thumb($data);
$file = array(
'img_name' => $data['raw_name'],
'thumb_name' => $data['raw_name'] . '_thumb',
'ext' => $data['file_ext'],
'type' => $this->input->post('type'),
'school' => $this->input->post('school'),
'email' => $this->input->post('email'),

);

$data = array('upload_data' => $this->upload->data());
$this->user_model->add_image($file);

// redirect('user/home_register');
$this->load->view('user/upload_success');
}
}
public function thumb($data) {
$config['image_library'] = 'gd2';
$config['source_image'] = $data['full_path'];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 275;
$config['height'] = 250;
$config['new_image'] = './thumbs/';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}

查看:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Technofest - user</title>
<?php echo link_tag('css/bootstrap.min.css'); ?>
<?php echo link_tag('jumbotron-narrow.css'); ?>

</head>

<body>
<br>
<div align="center">

</div>
<br>
<div class ="container">



<ul class="nav nav-pills nav-justified">

<li role="presentation"><a href="<?php echo base_url() . 'user/index';?>">Home</a></li>
<li role="presentation" ><a href="<?php echo base_url() . 'user/about';?>">About</a></li>
<li role="presentation"><a href="<?php echo base_url() . 'user/contact';?>">Contact</a></li>
<li role="presentation" class="active" ><a href="<?php echo base_url() . 'user/home_register';?>">Register</a></li>
</ul>
</div>

<br>
<br>
<div>
<?php echo form_open_multipart('user/do_upload'); ?>
<?php if (validation_errors()): ?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<?php echo validation_errors(); ?>
</div>
<?php endif ?>


<div class ="container center-block">

<div class="jumbotron">
<div class ="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Payment</h3>
</div>

<div class="panel-body">

<div class="form-group">
<div class="row">
<label class="col-sm-2 control-label">Type:</label>


<input type="radio" id="indiv" name="regtype" value="<?php echo set_value('type'); ?>" id='1'<?php echo set_radio('type','Individual', TRUE)?>/> Invidivual
<input id="bat" type="radio" name="regtype" value="<?php echo set_value('type'); ?>" id='2' <?php echo set_radio('type','Batch')?>/> Batch
<?php echo form_error('type'); ?>
<br><br>
<label class="col-sm-2 control-label">Payment for:</label>
</div>
</div>



<div class="form-group">
<div class="row">
<label class="col-sm-2 control-label">School:</label>
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="Enter School Name" name="school" value="<?php echo set_value('school'); ?>">
</div>
</div>
</div>
<?php echo form_error('school'); ?>


<div class="form-group">
<div class="row">
<label class="col-sm-2 control-label">Email:</label>
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="Enter Email" name="Email" value="<?php echo set_value('email'); ?>">
</div>
</div>
</div>
<?php echo form_error('email'); ?>
<input type="file" id="imgInp" name = "pic" required width = "10px">


<div class="col-sm-offset-2 col-sm-10">
<button type="button, submit" class="btn btn-primary " style="border-radius: 0;">
Upload
</button>


<a href="<?php echo base_url().'user/home_register';?>" type="button" class="btn btn-primary">Back</a>

</div>
<?php echo form_close() ?>

</div>
</div>


</div>


<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>

模型

function add_image($data) {
$this->db->set('payment_date', 'NOW()', FALSE);
$this->db->insert('payment', $data);
}

我在数据库中有 8 个字段id(自增),payment_data,type,school,email,img_name,thumb_name and ext

最佳答案

尝试将 pic 字段名称添加到

$this->upload->do_upload('pic')

并将 Raw Name 更改为 file_name

关于database - 上传带有图像的数据在 codeigniter 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35076450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com