0

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('/');
                }
		}

Edited by greenblack: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by saadi06
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.