如何在 codeigniter 3.0.1 中上传多个文件。 stackoverflow 中有类似的问题和解决方案,但不幸的是,它们都没有帮助解决我面临的问题。
这是我当前代码出现的错误消息 You did not select a file to upload
查看(添加图库)
<section>
<h2>Add Gallery</h2>
<?php echo form_open('Newsupload/gallery', ['id'=>'news', 'name'=>'news', 'method'=>'post','enctype'=>'multipart/form-data']) ?>
<div class="grp width-50">
<label for="name">Album Name</label>
<input type="text" name="name" id="name" value="" placeholder="">
</div>
<div class="grp width-100">
<div id="selectedFiles"></div>
<input type="file" id="files" name="files[]" multiple size="20"><br/>
</div>
<?php if (isset($error)) {
echo $error;
} ?>
<grp class="grp width-100">
<button>Add</button>
</grp>
</form>
</section>
Controller (图库)
public function gallery()
{
$this->load->library('upload');
$files = $_FILES;
$cpt = count($_FILES['files']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['files']['name']= $files['files']['name'][$i];
$_FILES['files']['type']= $files['files']['type'][$i];
$_FILES['files']['tmp_name']= $files['files']['tmp_name'][$i];
$_FILES['files']['error']= $files['files']['error'][$i];
$_FILES['files']['size']= $files['files']['size'][$i];
$this->upload->initialize($this->set_upload_options());
// $this->upload->do_upload('files[]');
if (!$this->upload->do_upload('files[]'))
{
$error =['error' => $this->upload->display_errors()];
$this->load->view('admin/addGallery', $error);
}
}
}
public function set_upload_options()
{
$config['upload_path'] = getcwd().'/upload/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['remove_spaces'] = true;
return $config;
}
最佳答案
默认情况下,codeIgniter 不支持多文件上传。所以你可以使用
这个库 CodeIgniter Multiple Upload Library
关于php - 如何在codeigniter 3.0.1中上传多个文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32964931/