我的变量将在我的数组中获得空值

时间:2019-05-16 11:39:33

标签: php mysql file codeigniter

我想上传文件并将文件名存储到我的数据库中,但是在此代码中,我的文件存储在我想要的位置,但是在数据库中我没有得到值,可能我的$ filename没有插入到data_insert数组中。 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);

1 个答案:

答案 0 :(得分:1)

您可以使用

方法1

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

方法2

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

有关CI DOC的更多详细信息。