我的表单中有两个文件上传控件,一个用于上传css文件,另一个用于html文件。我的 CSS 文件名是 style.css html 文件名是 test.html。
两个文件都已成功上传,但在上传时都使用相同的名称.css文件名在上传时是样式.css html 是文件名也是样式.css。
CSS文件上传代码是:
if(isset($_FILES['css_file']) AND $_FILES['css_file']['name'] != '') {
$xyz['upload_path'] = 'theme/'.$folder_name;
$xyz['allowed_types'] = 'css';
$xyz['overwrite'] = FALSE;
$xyz['file_name'] = $_FILES['css_file']['name'];
$this->load->library('upload', $xyz);
if (!$this->upload->do_upload('css_file')) {
echo $this->upload->display_errors();
}else{
$abc_array['file'] = $this->upload->data();
$array_rc['css_file'] = $abc_array['file']['file_name'];
}
}
HTML文件上传代码是:
if(isset($_FILES['html_file']) AND $_FILES['html_file']['name'] != '') {
$abc['upload_path'] = 'theme/'.$folder_name;
$abc['allowed_types'] = 'html';
$abc['overwrite'] = FALSE;
$abc['file_name'] = $_FILES['html_file']['name'];
$this->load->library('upload', $abc);
if (!$this->upload->do_upload('html_file')) {
echo $this->upload->display_errors();
}else{
$xyz_array['file'] = $this->upload->data();
$array_rc['html_file'] = $xyz_array['file']['file_name'];
}
}
那么如何在上传时重命名 html 文件?
看看这是否对你有帮助
$this->load->library("upload");
if(isset($_FILES['css_file']) AND $_FILES['css_file']['name'] != '')
{
$xyz['upload_path'] = 'theme/'.$folder_name;
$xyz['allowed_types'] = 'css';
$xyz['overwrite'] = FALSE;
$xyz['file_name'] = $_FILES['css_file']['name'];
$this->upload->initialize($xyz);
if (!$this->upload->do_upload('css_file'))
{
echo $this->upload->display_errors();
}
else
{
print_r($this->upload->data());
}
}
if(isset($_FILES['html_file']) AND $_FILES['html_file']['name'] != '')
{
$abc['upload_path'] = 'theme/'.$folder_name;
$abc['allowed_types'] = 'html';
$abc['overwrite'] = FALSE;
$abc['file_name'] = $_FILES['html_file']['name'];
$this->upload->initialize($abc);
if (!$this->upload->do_upload('html_file'))
{
echo $this->upload->display_errors();
}
else
{
print_r($this->upload->data());
}
}
原生
$config['encrypt_name'] = TRUE;
或
$name = $_FILES["userfiles"]['name'];
$config['file_name'] = $name;