这是文件上传的codeigniter功能
public function doctor_signup()
{
$this->load->library('encrypt');
$rand = time() . rand(0, 9999);
if($_FILES["file"]["name"]!="")
{
$config['upload_path'] = realpath(dirname(__FILE__)). '/uploads/';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['name']=$rand;
print_r($config);
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
echo $error = array('error' => $this->upload->display_errors());
exit;
}
}
$data = array(
'username' => $_POST['username'],
'password' => $this->encrypt->encode($_POST['password']),
'name' => $_POST['name'],
'address' => $_POST['address'],
'city' => $_POST['city'],
'state' => $_POST['state'],
'photo'=> $rand,
'email' => $_POST['email'],
'date_of_join'=>date('Y-m-d H:m:s'),
'landline' => $_POST['landline'],
'mobile' => $_POST['mobile'],
'specialist' => $_POST['specialist'],
'comments' => $_POST['comments'],
'degree' => $_POST['degree']
);
if( $this->db->insert('doctor_user', $data))
{
$this->load->view('header', $data);
$this->load->view('user_created', $data);
$this->load->view('footer', $data);
}
}
但该文件未上传到上传目录,也没有出现任何错误。主目录下的uploads文件夹。任何建议。 感谢
答案 0 :(得分:0)
我认为可能是因为$ config ['name']应该是
$config['file_name']
尝试重命名,看看它是否有效。您也没有使用$ config ['allowed_types']来指定可以上传的文件。否则是什么阻止某人上传一个讨厌的文件?