Welcome Guest, Not a member yet? Register   Sign In
.doc and .docx file upload
#11

@ Paradinight

Hi as per your advise i updated my codeigniter version now its 3.1.2 but still have issue.
Reply
#12

Hi,

You should post your method that handles the upload, has a few more pair of eyes may see something in your code.
A good decision is based on knowledge and not on numbers. - Plato

Reply
#13

(This post was last modified: 11-09-2016, 03:30 AM by rupamhazra.)

@salain

Here is my controller code below.also i attached the form view.

public function profile_pic()
{
$this->load->view('header');
$error="";
$id=!empty($this->session->userdata('last_insert_id')) ? $this->session->userdata('last_insert_id') : $this->input->post('id');

if($this->input->post('upload'))
{
//echo $id;
//exit();
$config['upload_path']          = './uploads/';
       $config['allowed_types']        = 'gif|jpg|png|doc|pdf|docx';
       $config['max_size']             = 2000;
       $config['max_width']            = 2000;
       $config['max_height']           = 1500;
       $this->load->library('upload', $config);
       $this->upload->initialize($config);
       $error="";
       if ( ! $this->upload->do_upload('userfile') && !$this->input->post('pic'))
       {
           $error = array('error' => $this->upload->display_errors());
           //$this->load->view('profile_pic',$error);
       }
       else
       {
        $data = array('upload_data' => $this->upload->data());
        $post_data=array(
'pic' =>!empty($_FILES["userfile"]["name"])? $_FILES["userfile"]["name"] : $this->input->post('pic')
//'password' => $password
);
        $response=$this->user_model->insert_pic($post_data,$id);
if($response)
{
$this->session->set_flashdata(array('msg' => 'Saved data successsfully','status'=>false));
redirect('usersite');
}
       }
}
$this->load->view('profile_pic',$error);
$this->load->view('footer');
}

Attached Files
.php   profile_pic.php (Size: 875 bytes / Downloads: 127)
.php   mimes.php (Size: 9.82 KB / Downloads: 134)
Reply
#14

Your method is named profile_pic() it should be named do_upload()
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#15

(11-09-2016, 03:29 AM)rupamhazra Wrote: @salain

Here is my controller code below.also i attached the form view.

public function profile_pic()
{
$this->load->view('header');
$error="";
$id=!empty($this->session->userdata('last_insert_id')) ? $this->session->userdata('last_insert_id') : $this->input->post('id');

if($this->input->post('upload'))
{
//echo $id;
//exit();
$config['upload_path']          = './uploads/';
       $config['allowed_types']        = 'gif|jpg|png|doc|pdf|docx';
       $config['max_size']             = 2000;
       $config['max_width']            = 2000;
       $config['max_height']           = 1500;
       $this->load->library('upload', $config);
       $this->upload->initialize($config);
       $error="";
       if ( ! $this->upload->do_upload('userfile') && !$this->input->post('pic'))
       {
           $error = array('error' => $this->upload->display_errors());
           //$this->load->view('profile_pic',$error);
       }
       else
       {
        $data = array('upload_data' => $this->upload->data());
        $post_data=array(
'pic' =>!empty($_FILES["userfile"]["name"])? $_FILES["userfile"]["name"] : $this->input->post('pic')
//'password' => $password
);
        $response=$this->user_model->insert_pic($post_data,$id);
if($response)
{
$this->session->set_flashdata(array('msg' => 'Saved data successsfully','status'=>false));
redirect('usersite');
}
       }
}
$this->load->view('profile_pic',$error);
$this->load->view('footer');
}

Is the docx a real docx? You can not change the name from test.txt to test.docx and upload. It will fail. Can you show us the file?

The check of the mime_type of the file: https://github.com/bcit-ci/CodeIgniter/b....php#L1216
Copy some parts to a test controller and check what you get.

@InsiteFX the controller method can be named to anything. The thread owner has only problems with doc/docx.
Reply
#16

(11-09-2016, 02:07 PM)Paradinight Wrote:
(11-09-2016, 03:29 AM)rupamhazra Wrote: @salain

Here is my controller code below.also i attached the form view.

public function profile_pic()
{
$this->load->view('header');
$error="";
$id=!empty($this->session->userdata('last_insert_id')) ? $this->session->userdata('last_insert_id') : $this->input->post('id');

if($this->input->post('upload'))
{
//echo $id;
//exit();
$config['upload_path']          = './uploads/';
       $config['allowed_types']        = 'gif|jpg|png|doc|pdf|docx';
       $config['max_size']             = 2000;
       $config['max_width']            = 2000;
       $config['max_height']           = 1500;
       $this->load->library('upload', $config);
       $this->upload->initialize($config);
       $error="";
       if ( ! $this->upload->do_upload('userfile') && !$this->input->post('pic'))
       {
           $error = array('error' => $this->upload->display_errors());
           //$this->load->view('profile_pic',$error);
       }
       else
       {
        $data = array('upload_data' => $this->upload->data());
        $post_data=array(
'pic' =>!empty($_FILES["userfile"]["name"])? $_FILES["userfile"]["name"] : $this->input->post('pic')
//'password' => $password
);
        $response=$this->user_model->insert_pic($post_data,$id);
if($response)
{
$this->session->set_flashdata(array('msg' => 'Saved data successsfully','status'=>false));
redirect('usersite');
}
       }
}
$this->load->view('profile_pic',$error);
$this->load->view('footer');
}

Is the docx a real docx? You can not change the name from test.txt to test.docx and upload. It will fail. Can you show us the file?

The check of the mime_type of the file: https://github.com/bcit-ci/CodeIgniter/b....php#L1216
Copy some parts to a test controller and check what you get.

@InsiteFX the controller method can be named to anything. The thread owner has only problems with doc/docx.

@Paradinight
I have attached the sample file which i want to upload.Please check

Attached Files
.docx   sample1.docx (Size: 25 bytes / Downloads: 127)
.doc   user.doc (Size: 129 bytes / Downloads: 119)
Reply
#17

(This post was last modified: 11-09-2016, 09:51 PM by rupamhazra.)

@Paradinight

Hey,  you are right that the doc and docx file which i want to upload this ins not real doc and docx. i am checking and found that the these files are not real.Huh

Thanks for giving idea.

Also thanks to @all who want to help me. 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB