我制作了一个代码,可以让我上传多个文件但分开
我试图在一个输入中上传多个文件,我将输入标签设置为
<input type="file" multiple="" name="file1">
我选择了 3 张图片,但只上传了 1 张图片。
这是我在更改输入之前的视图:
<?php echo form_open_multipart('test'); ?>
<p>
<?php echo form_label('File 1: ', 'file1') ?>
<input type='file' name='file1' id='file1'>
</p>
<p>
<?php //echo form_label('File 2: ', 'file2') ?>
<input type='file' name='file2' id='file2'>
</p>
<p><?php echo form_submit('submit', 'Upload them files!') ?></p>
这是我的控制器
function index()
{
if (isset($_POST['submit']))
{
$this->load->library('upload');
$config['upload_path'] = './upload_documents/';
$config['allowed_types'] = 'jpg|png|gif|jpeg|JPG|PNG|GIF|JPEG';
$config['max_size'] = '0'; // 0 = no file size limit
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['overwrite'] = TRUE;
$this->upload->initialize($config);
foreach($_FILES as $field => $file)
{
// No problems with the file
if($file['error'] == 0)
{
// So lets upload
if ($this->upload->do_upload($field))
{
$data = $this->upload->data();
//alert("nice");
}
else
{
$errors = $this->upload->display_errors();
die();
}
}
else{
echo "alksjdfl";
die();
}
}
}
$this->load->view("test");
}
}