我的表单中有两个文件上传控件,一个用于上传css文件,另一个用于html文件。 我的css文件名是style.css,html文件名是test.html。
两个文件都已成功上传,但在上传时都采用相同的名称。 css文件名是在上传时是style.css而html是文件名也是style.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文件?
答案 0 :(得分:1)
看看这有助于你
$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());
}
}
答案 1 :(得分:0)
本地
$config['encrypt_name'] = TRUE;
OR
$name = $_FILES["userfiles"]['name'];
$config['file_name'] = $name;