我正在使用codeigniter。我想在表单中上传带有两个文件输入字段的文件。我的代码正确地上传了我的目录中的文件,但是在模型函数参数中没有geting文件名。
我的代码
$config['upload_path'] = './uploads';
$config['allowed_types'] = 'jpg|png|jpeg|gif';
$config['max_size'] = '0';
$config['encrypt_name'] = True;
$up=$this->load->library('upload', $config);
$fileNameheaderimage = $this->upload->data();
$config2['upload_path'] = './uploads';
$config2['allowed_types'] = 'jpg|png|jpeg|gif';
$config2['max_size'] = '0';
$config2['encrypt_name'] = True;
$up2=$this->load->library('upload', $config2);
$fileNameprofileimage = $this->upload->data();
if (!$this->upload->do_upload('headerimage') || !$this->upload->do_upload('profileimage') )
{
$status = "0";
$msg = "File upload failed";
}
else
{
$result = $this->api_model->updateprofileinfo($fileNameheaderimage['file_name'],$fileNameheaderimage['file_name']);
if($result)
{
$status = "1";
$msg = "File uploaded";
}
else
{
$status = "0";
$msg = "File upload failed";
}
}
此处文件名为空
$this->api_model->updateprofileinfo($fileNameheaderimage['file_name'],$fileNameheaderimage['file_name']);
答案 0 :(得分:0)
无需再次加载upload
库$this->load->library('upload');
使用initilize()
方法更改配置
$this->upload->initialize($config)
//and
$this->upload->initialize($config2)
在你的情况下,第一个配置用第二个配置覆盖所以它不起作用,试试这个
$this->load->library('upload');
$this->upload->initialize($config)
$status1 = true; $status2 = true;
if (!$this->upload->do_upload('headerimage') )
{
$status1 = "0";
}
$this->upload->initialize($config2)
if(!$this->upload->do_upload('profileimage'){
$status2 = "0";
}
if($status1 == true || $status2 == true){
$msg = "File uploaded";
}else{
$msg = "File not uploaded";
}