我想通过生成的编号上传字段上传带有CodeIgniter的文件:
<input type='file' name='field[0]' />
<input type='file' name='field[1]' />
这些上传字段属于另一个输入字段:
<input type='file' name='field[0]' />
<input type='TEXT' name='field[1]' />
<input type='file' name='field[2]' />
我只想在用户点击“提交”按钮时上传文件并保留此特定输入结构
我试过这个,但它不起作用:
for($i=0; $i<count($_FILES); $i++)
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['overwrite'] = FALSE;
$this->upload->initialize($config);
$this->upload->do_upload('field['.$i.']');
}
任何帮助都将非常感谢!谢谢!
答案 0 :(得分:1)
这就是诀窍:
foreach ($_FILES['field']['name'] as $i => $name) {
if ($_FILES['field']['error'][$i] == 4) {
continue;
}
if ($_FILES['field']['error'][$i] == 0) {
if ($_FILES['field']['size'][$i] > 99439443) {
$message[] = "$name exceeded file limit.";
continue;
}
/*
* Check File Extension
* Move File
*/
echo $name;
echo '<br />';
$uploads_dir = $config['upload_path'] = './uploads/thumbs/'.$this->session->userdata('raw_name');
$tmp_name = $_FILES["field"]["tmp_name"][$i];
$name = $_FILES["field"]["name"][$i];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
不幸的是,不是以CodeIgniter方式:(它不起作用,我不知道为什么,但这很好用