大家好,
我正在尝试上传数据库中的文件路径,但它正在重定向相同的文件,并且文件没有上传,任何人都可以帮助我.. 这是我的控制器。
<?php
if (!defined ('BASEPATH'))exit('no direct scripts allowed ');
class Main extends CI_Controller
{
function __construct ()
{
parent::__construct();
$this->load->library('session');
}
function insert_quiz_data()
{
$this->load->library('form_validation'); //loading validation library
$this->form_validation->set_rules('qtitle','quiz_title'); //setting rules for validation
$this->form_validation->set_rules('qcategory1','quiz_category1');
$this->form_validation->set_rules('qcategory2','quiz_category2');
$this->form_validation->set_rules('qcategory3','quiz_category3');
$this->form_validation->set_rules('astatus','email');
$this->form_validation->set_rules('userfile', 'quiz_image_path', 'callback__do_upload'); //userfile is the upload file field name in form ,
echo 'testing';
if($this->form_validation->run()!=false)
{
//Get the info from the form
$username = $this->input->post('qtitle');
$password = $this->input->post('qcategory1');
$passconf = $this->input->post('qcategory2');
$date = $this->input->post('qcategory3');
$email = $this->input->post('astatus');
$temp=$this->upload->data();
$image=$temp['file_name'];// to get image file name rom upload script , as it could be stored in the databae
//load the model
$this->load->model('quiz_mode');
//execute the registration query
$data = $this->quiz_mode->register_user($username,$password,$passconf,$date,$image,$email);
//if $data == TRUE
if($data)
{
echo "you have successfully made your registration";
$this->load->view('logged_in_area');
}
else
{
echo "faillled";
}
}
else{
//You arrived here just in case the form fields are not correct
$this->load->view('logged_in_area'); //loading reg form here
}
}
public function _do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$field_name = 'userfile';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload($field_name))
{
$this->form_validation->set_message('_do_upload', $this->upload->display_errors());
return FALSE;
}
else
{
$image_data = $this->upload->data();
$filename = $image_data['file_name'];
$config = array
(
'source_image' => $image_data['full_path'],
'new_image' => './uploads/thumbs/',
'maintain_ratio' => false,
'width' => 300,
'height' => 200
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
return TRUE;
}
}
}
我的模特班:
<?php
class File_model extends CI_Model
{
function File_model()
{
parent::__construct();
}
function register_user($username,$password,$passconf,$date,$image,$email)
{
$data= array('username'=>$username,
'password'=>$password,
'passconf'=>$passconf,
'date'=>$date,
'image'=>$image,
'email'=>$email
);
$res= $this->db->insert('register', $data); //register is my table name
return $res;
var_dump($res);
}
}
?>
我的观点
<html>
<body>
<?php $this->load->helper('form'); ?>
<?php echo form_open_multipart('index.php/main'); ?>
<?php echo validation_errors(); ?>
<table width="348" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center"><h2><strong>REGISTERATION AREA</strong></h2></td>
</tr>
<tr><?php //echo validation_errors(); ?>
<td width="97" height="40"><label for"username"> <strong>Username </strong></label></td>
<td width="249"><input type="text" id="username" name="username" value="<?php echo set_value('username'); ?>"/></td>
</tr>
<tr>
<td><label for"password"> <strong>Password </strong></label></td>
<td><input type="password" name="password" id="password" value="<?php echo set_value('password'); ?>"/></td>
</tr>
<tr>
<td><label for"confirm password"> <strong>Passconf</strong></label></td>
<td><input type="password" name="passconf" id="passconf" value="<?php echo set_value('passconf'); ?>"/></td>
</tr>
<tr>
<td><label for"date "><strong>Date</strong></label></td>
<td><input type="text" name="datepicker" id="datepicker" /></td>
</tr>
<tr>
<td><strong>Upload Picture</strong></td>
<td><input type="file" name="userfile" size="20" id="userfile" /></td>
</tr>
<tr>
<td><label for"email"> <strong>Email</strong></label></td>
<td><input type="text" name="email" value="<?php echo set_value('email'); ?>"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="44"> </td>
<td align="center">
<input type="submit" id="submit" value="Register" /></td>
</tr>
</table>
</body>
</html>
谁能帮我 。谢谢。