anyone please help me, whats wrong with this code:

this is codeigniter, i can't upload file with this code/script:

class MUpload extends Model{
	function MUpload()
		{
			parent::Model();
		}
	
	function upload()
		{
            
			$data = array(
				'my_file' => $_POST['userfile'],
				'my_user' => $this->authniter->getUsername(), //this is user login name with my library 'authniter'
			);
            if(is_dir('./upload/'))
                {
                    if(is_dir('./upload/'.$data['my_user'].'/') == false)
                        {
												mkdir('./upload/'.$data['my_user'].'/');
										  }
                    else
                        {
                            $config['upload_path'] = './upload/'.$data['my_user'].'/';
                            $config['allowed_types'] = 'xls|xlsx|xml|csv|txt';
                            $config['max_size'] = '10000';
                            $config['remove_spaces'] = true;
                            $config['overwrite'] = false;
                            $config['max_width'] = '0';
                            $config['max_height'] = '0';
                            $this->load->library('upload', $config);
                            
                            $data['file_upload'] = $this->config->item('base_url').'./upload/'.$data['my_user'].'/'.$_POST['userfile'];
												if(!$this->upload->do_upload('userfile')){ //name of upload field from view is 'userfile'
														$error = $this->upload->display_errors();
														echo $error;
														$this->upload->do_upload('userfile');
												}
												else
														{
															$this->upload->do_upload('userfile');
														}
                            $this->db->insert('treferences', $data);        
                        }
                }
            else
                {
                    $this->CI->session->set_flashdata('notification',"your upload dir, not exist !, contact this system administrator !");
                    redirect('/');
                }
		}

Recommended Answers

All 3 Replies

Have you checked your max file size in php.ini and also check that the form has enctype="multipart/form-data" this attribute in your view

many thank's. i forget to write enctype="multipart/form-data" :)

no problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.