codeigniter在数据库中上载图像存储用户文件,而不是图像名称
而不是 控制器: 我的上传目录很好,但当我使用另一种方法并在需要时调用它时,它不会给出我想要的输出。。我为这件事感到非常抱歉 ` 视图:codeigniter在数据库中上载图像存储用户文件,而不是图像名称,codeigniter,image-upload,Codeigniter,Image Upload,而不是 控制器: 我的上传目录很好,但当我使用另一种方法并在需要时调用它时,它不会给出我想要的输出。。我为这件事感到非常抱歉 ` 视图: 您没有指定输入,也没有向函数返回图像的名称 function uploadImage() { $config['upload_path'] = './uploads/files'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '2048'
您没有指定输入,也没有向函数返回图像的名称
function uploadImage() {
$config['upload_path'] = './uploads/files';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile')){
$error = array('error' => $this->upload->display_errors());
// var_dump($error); die; // check error
} else {
$fileName = $this->upload->data();
return $fileName;
}
}
function signupPost() {
if ($this->form_validation->run('signup') == FALSE) {
// fails wont continue to next page
$this->signup_view();
} else {
// upload image
$data['UserFile'] = $this->uploadImage();
// insert data into the database
$data = array(
'userId' => $this->input->post('userId'),
'password' => $this->input->post('password'),
'emailAddress' => $this->input->post('emailAddress'),
'userfile' => $this->input->post('userfile'),
'branchId' => $this->input->post('branchId')
);
// user data has successfully signed up
$this->User->signup_client($data);
redirect('http://localhost/GFC/index.php/main', 'refresh');
}
}
感谢您的快速回答@muhammadusman。这意味着很多。还有其他可能的原因吗?就像我设置数据库结构的方式一样?。。。没有成功。显示您的数据库结构?没有错误,但数据库中的输出是“userfile”,而不是图像的名称。列:userfile,varchar 255,MIME类型:noneecho$post_image;死亡检查varibale中存储的内容
public function signupPost()
{
if ($this->form_validation->run('signup') == FALSE) {
//fails wont continue to next page
$this->signup_view();
} else {
//upload image
$this->uploadImage();
//insert data into the database
$data = array(
'userId' => $this->input->post('userId'),
'userfile' => $this->input->post('userfile'),
);
//user data has successfully signed up
$this->User->signup_client($data);
redirect('http://localhost/GFC/index.php/main','refresh');
}
}
<?php
$attributes = array("name" => "signupform");
$hidden = array('userId' => 'userId', 'userfile' => 'userfile');
echo form_open_multipart("Client_Dashboard/signupPost", $attributes, $hidden);
?>
<div class="w3-row">
<input type="file" name="userfile" size="20" style="margin-left:30%; margin-top:8%;"/>
<span class="text-danger"><?php echo form_error('userfile'); ?></span>
</div>
<div class="container" style="padding:0%;">
<br>
<input type="submit" value="Register" class=" w3-btn w3-teal w3-large w3-hover-white w3-padding-large" />
</div>
<?php echo form_close(); ?>
function uploadImage() {
$config['upload_path'] = './uploads/files';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile')){
$error = array('error' => $this->upload->display_errors());
// var_dump($error); die; // check error
} else {
$fileName = $this->upload->data();
return $fileName;
}
}
function signupPost() {
if ($this->form_validation->run('signup') == FALSE) {
// fails wont continue to next page
$this->signup_view();
} else {
// upload image
$data['UserFile'] = $this->uploadImage();
// insert data into the database
$data = array(
'userId' => $this->input->post('userId'),
'password' => $this->input->post('password'),
'emailAddress' => $this->input->post('emailAddress'),
'userfile' => $this->input->post('userfile'),
'branchId' => $this->input->post('branchId')
);
// user data has successfully signed up
$this->User->signup_client($data);
redirect('http://localhost/GFC/index.php/main', 'refresh');
}
}