我想以我的名字上传两张图片
$config['upload_path'] = '/path/to/file';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['file_name'] ='logo1_'.$_POST['name'];
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('image1'))
{...}
else
{
$data = $this->upload->data();
}
$config2['upload_path'] = '/path/to/file';
$config2['allowed_types'] = 'gif|jpg|png';
$config2['max_size'] = '0';
$config2['file_name'] = 'logo2_'.$_POST['name'];
$config2['max_width'] = '0';
$config2['max_height'] = '0';
$this->load->library('upload', $config2);
if ( ! $this->upload->do_upload('image2'))
{...}
else
{
$data = $this->upload->data();
}
我的第一张图片正确保存在我的文件夹中,名称为logo1_myname
,但我的第二张图片不保存为logo2_myname
,另存为logo1_myname1
我的代码出了什么问题?
答案 0 :(得分:1)
更改
$this->load->library('upload', $config2);
到
$this->upload->initialize($config2);
由于该类已经加载,codeigniter将不再加载它。
希望这有帮助。