【发布时间】:2017-11-23 20:23:59
【问题描述】:
我在上传多个不同区域名称的文件时遇到问题,我想在上传之前更改每个区域的文件名。
这是 HTML 表单。
<input type="file" placeholder="" name="profilPic"/>
<input type="file" placeholder="" name="topPic"/>
这是控制器
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
//$config['file_name'] = $this->session->sersession["id"];
$this->load->library('upload', $config);
$profilPic = $this->upload->do_upload('profilPic');
if (!$profilPic){
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata("error", "profil pic was not uploaded= ");
}else{
$data = array('upload_data' => $this->upload->data());
$this->session->set_flashdata("success", "profil picture was uploaded.");
}
$topPic = $this->upload->do_upload('topPic');
if (!$topPic){
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata("error", "top pic was not uploaded" );
}else{
$data = array('upload_data' => $this->upload->data());
$this->session->set_flashdata("success", "this picture was uploaded.");
}
注意:图片上传到目录。但我想在上传之前重命名每个文件的文件名,如“userID_profil.jpg”和“userID_top.jpg”
【问题讨论】:
标签: php codeigniter file-upload