Я искал и боролся в течение 3 дней, чтобы сделать это, но я просто не могу. То, что я хочу сделать, это использовать форму ввода нескольких файлов, а затем загрузить их. Я не могу просто использовать фиксированное количество файлов для загрузки. Я попробовал много решений на StackOverflow, но я не смог найти рабочий.
Здесь мой контроллер загрузки
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url','html'));
}
function index()
{
$this->load->view('pages/uploadform', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './Images/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload');
foreach($_FILES['userfile'] as $key => $value)
{
if( ! empty($key['name']))
{
$this->upload->initialize($config);
if ( ! $this->upload->do_upload($key))
{
$error['error'] = $this->upload->display_errors();
$this->load->view('pages/uploadform', $error);
}
else
{
$data[$key] = array('upload_data' => $this->upload->data());
$this->load->view('pages/uploadsuccess', $data[$key]);
}
}
}
}
}
?>
Моя форма загрузки - это.
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" multiple name="userfile[]" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
Я просто продолжаю эту ошибку:
Вы не выбрали файл для загрузки.
Здесь массив примера:
Array ([userfile] = > Array ([name] = > Array ([0] = > youtube.png [1] = > zergling.jpg) [type] = > Array ([0] = > изображение /png [1] = > image/jpeg) [tmp_name] = > Array ([0] = > E:\wamp\tmp\php7AC2.tmp [1] = > E:\wamp\tmp\php7AC3.tmp) [ошибка ] = > Массив ([0] = > 0 [1] = > 0) [size] = > Array ([0] = > 35266 [1] = > 186448)))
У меня это есть 5 раз подряд, если я выбираю 2 файла. Я также использую стандартную библиотеку загрузки.