【发布时间】:2017-07-04 14:57:25
【问题描述】:
Database output: userfile rather than image name? 而不是 控制器: 我的上传目录很好,但是当我使用另一种方法并在需要时调用它时,它并没有给出我想要的输出。我很抱歉新手
`
public 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()){
$error = array('error' => $this->upload->display_errors());
echo "<script>window.alert('failed to load UserFile');</script>";
}else{
$data = array('upload_data' => $this->upload->data());
$post_image = $_FILES['userfile']['name'];
echo "<script>window.alert('your image has been successfully uploaded');</script>";
}
}
`
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(); ?>
【问题讨论】: