1

I want to upload file and store name of file into my database but here in this code my file is stored at my desired location but in database i am not getting value probably my $filename is not getting inserted into my data_insert array. input->post('pic_file');

//$pic_file1 = str_replace( "\\", '/', $pic_file1);
// $filename = time().basename($pic_file1);
//$filename = "";

$config['upload_path']   = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']      = 1000;
$config['encrypt_name']  = true;
// $config['overwrite'] = FALSE;
//$config['file_name'] =  $filename;

$this->load->library('upload', $config);
$this->upload->initialize($config);

if (!$this->upload->do_upload('pic_file')) {
    $error = array('error' => $this->upload->display_errors());
    print_r($error);
} else {
    $data     = array('upload_data' => $this->upload->data());
    $filename = $data['upload_data']['file_name'];

    // print_r($data);
    // $first_names = array_column($data, 'file_name');
    //print_r($first_names);
    //$file_name =  implode(" ",$first_names);

} //die();
echo $filename;

//die();
$data_insert = array(
    'setpassword' => $setpassword,
    'conpassword' => $conpassword,
    'city'        => $city,
    'products'    => $products,
    'bank_type'   => $bank_type,
    'bank_name'   => $bank_name,
    'dsa_code'    => $dsa_code,
    'pic_file'    => $filename,
);

$this->db->where('id', $dataId);
$this->db->update('tbl_reg_dsa', $data_insert);
4
  • 1
    do 1 thing. print_r($this->upload->data()); check you are getting file_name in array Commented May 16, 2019 at 11:48
  • i am getting filename in $filename variable but whenever i pass that $filename into my $data_insert array at that time i get blank value into my database Commented May 16, 2019 at 11:51
  • $dataId is not defined in your code snippet, so we don't know what it's value? Commented May 16, 2019 at 15:29
  • use it like that $upload_data = $this->upload->data(); $filename = $upload_data['file_name']; Commented May 21, 2019 at 8:06

1 Answer 1

1

You can fetch that using

Method 1

$temp = $this->upload->data();
echo $temp['orig_name']; // or file_name

Method 2

$this->upload->data('pic_file'); // should return name of file

Here is more details about CI DOC.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.