问题在于,当我上传文件时,它会用下划线替换它的空格。 因为,我从ajax获取url所以第一个字符串是:
$last = $this->uri->total_segments();
echo $this->uri->segment($last);
EOLU%2012345671545052
使用PHP:
$id = rawurldecode($this->uri->segment($last));
echo $id;
EOLU 12345671545052
我正在上传多个文件。如果上传了3个文件,我想给出这样的名字:
EOLU 12345671545052 0
EOLU 12345671545052 1
EOLU 12345671545052 2
但在查看我的上传目录后,我看到了类似的内容:
EOLU_12345671545052_0
EOLU_12345671545052_1
EOLU_12345671545052_2
这是我的完整代码:
$last = $this->uri->total_segments();
$id = rawurldecode($this->uri->segment($last));
$pathToUpload = './assets/uploads/' . $id;
for ($i = 0; $i < $number_of_files; $i++) {
$_FILES['file']['name'] = $files['file']['name'][$i];
$_FILES['file']['type'] = $files['file']['type'][$i];
$_FILES['file']['tmp_name'] = $files['file']['tmp_name'][$i];
$_FILES['file']['error'] = $files['file']['error'][$i];
$_FILES['file']['size'] = $files['file']['size'][$i];
// we have to initialize before upload
$config['file_name'] = $id . " ".$i; //Gives name of each file
echo $config['file_name'];
$this->upload->initialize($config);
if (!$this->upload->do_upload("file")) {
$errors++;
}
}
我试过了:
$config['file_name'] = str_replace("_", " ", $id) . $i;
但它仍然给我下划线。我在哪里错过了? 谢谢。
答案 0 :(得分:1)
试试这个:
$config['remove_spaces'] = false;