Codeigniter当我在注册表单中使用enctype=“multipart/form-data”时,照片不会保存在数据库中,而是照片会上传到上传文件夹。然后当我删除enctype=“多部分/表单数据”照片保存在数据库中,但照片不来上传文件夹。如果这是代码的问题,请执行完整代码。因为我不是一个好的开发人员。
视图
<form method="post" action="family_join" enctype="multipart/form-data" id="wizard">
<h4 class="text-center mb-4 mt-4">Upload Photo</h4>
<div class="form-group mt-3 mb-4">
<div class="dropzone-wrapper">
<div class="dropzone-desc">
<i class="glyphicon glyphicon-download-alt"></i>
<p>Choose an image file or drag it here.</p>
</div>
<input type="file" name="photo" class="dropzone">
</div>
</div>
<h4 class="text-center mb-4">Please enter the zipcode</h4>
<div class="default-form contact-form">
<div class="form-group">
<input type="text" name="zipcode" placeholder="Enter Zip Code" required>
</div>
</div>
</form>
控制器
< ? php
defined('BASEPATH') OR exit('No direct script access allowed');
Class Family_Join extends CI_Controller {
public
function __construct() {
parent::__construct();
$this->load-> helper(array('form', 'url'));
}
public
function index() {
$this->form_validation-> set_rules('zipcode', 'Zipcode', 'required|min_length[4]');
if ($this->form_validation->run()) {
$zipcode=$this->input->post('zipcode');
$photo=$this->input->post('photo');
$status = 1;
$this->load->model('Family_Join_Model');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$this->upload->do_upload('photo');
$this-> Family_Join_Model->insert($zipcode, $photo, $status);
} else {
$this->load->view('user/family_join', array('error' => ' '));
}
}
}
守候你守候我
莫回无
慕尼黑5688855