我已经创建了一个用于登录和上传的查看页面,但是当我按下“提交”按钮时,它并没有上传到我的数据库中。
我用过insert()命令。
这是我的控制器,我已经使用 $ this-> load-> model('upanel_model');现在,我想进行编码,以便每当用户按下“提交”按钮时,数据就会插入数据库中。
public function upload_post(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = '$pdfname';
$this->load->library('upload',$config);
if(!$this->upload->do_upload('userfile')){
$error = array('error' => $this->upload->display_errors());
}
else{
$data1 = array('upload_data' => $this->upload->data());
$data = $this->upload->data('full_path');
$pdfType = $data1['upload_data']['file_ext'];
$pdf_link = $pdfName.$pdfType;
$table = 'register';
$data['email']=$this->post('email');
$data['password']= $this->post('password');
$data['file_path']=$pdf_link;
$data2 = $this->upload->data('full_path');
$userdata=$this->$model_name->insert($table,$data);
if($userdata){
$data_response['status']=1;
$data_response['msg']="Successfully inserted details";
$this->response($data_response);
} else{
$data_response['status']=0;
$data_response['msg']="Unable To insert details";
$this->response($data_response);
}
}
public function upload_get(){
$this->load->view('view');
}
这是我的名为upanel_model.php的模型,它可以插入数据
<?php
function insert($table,$data){
$this->db->insert($table,$data);
return $this->db->insert_id();
}
?>
这是名为view.php的视图,该视图调用了我的上传API
<body>
<?php echo form_open_multipart('uPanel/do_upload'); ?>
<div class = "header">
<h1>Login Now</h1>
</div>
<form method= "post" action= "upload">
<div class="input-group">
<label>email</label>
<input type="text" name="email" >
</div>
<div class ="input-group">
<label>Password</label>
<input type="text" name="password">
</div>
<div class = "input-group">
<input type="submit" class ="btn" name="login_now" value="submit" >
</div>
<p> NOT MEMBER? SIGN UP
</p>
<input type="file" name="userfile" size="90" />
<br /><br />
<input type="submit" value="upload" />
</body>