我在这里附上欲望问题的代码。Cotroller具有以下代码。控制器=>
//Load upload library
$this->load->library('upload');
$images = array();
$i = 0;
foreach ($_FILES as $key => $value)
{
$tmp = explode(".",$value['name'][$i]);
$imagename = time().".".end($tmp);
$_FILES['file']['name'] = $imagename;
$_FILES['file']['type'] = $value['type'][$i];
$_FILES['file']['tmp_name'] = $value['tmp_name'][$i];
$_FILES['file']['error'] = $value['error'][$i];
$_FILES['file']['size'] = $value['size'][$i];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = $imagename;
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('file'))
{
$error = array($i => $this->upload->display_errors());
echo "<pre>";print_r($error);die;
}
else
{
array_push($images,$this->upload->data()['file_name']);
}
$i++;
}
echo "<pre>";print_r($images);die;
这是我在上传文件时使用的表单代码。查看=>
<?php $attributes = array(
"class" => "form-horizontal m-t-20",
"method" => "post",
"novalidate" => "",
"enctype" => "multipart/form-data"
);
echo form_open('admin/user/adduser', $attributes); ?>
这是我的文件输入控件。
<label for="file">Profile Images*</label>
<input type="file" name="files[]" id="file" multiple required placeholder="Profile Images" class="form-control">
如下更改代码
foreach($_FILES["files"]["tmp_name"] as $key=>$value) {
和变革$i
的$key
如下(适用于所有)
$_FILES['file']['type'] = $_FILES["files"]['type'][$key];
如瓦扎比建议的那样,在文件名后附加一些随机字符串。您可以使用rand(100,10000)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句