我有使用单文件上传的经验<input type="file">.但是,我无法一次上传多个.
例如,我希望能够一次性选择一系列图像,然后将它们上传到服务器.
如果可能的话,使用单个文件输入控件会很棒.
有谁知道如何做到这一点?谢谢!
我一直在寻找并努力工作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]);
}
}
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我的上传表格是This.
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php …Run Code Online (Sandbox Code Playgroud) 我正在尝试在文件夹中上传多个文件,但它会显示错误"您没有选择要上传的文件".
遇到PHP错误
严重性:警告
消息:is_uploaded_file()期望参数1为字符串,给定数组
文件名:libraries/Upload.php
行号:412
回溯:
文件:C:\ wamp\www\mshaadi\application\controllers\Email.php行:55功能:do_upload
文件:C:\ wamp\www\mshaadi\index.php行:293功能:require_once
调节器
$conf['upload_path'] = './images';
$conf['allowed_types'] = 'doc|docx|pdf|jpg|gif|jpeg|png';
$conf['max_size'] = '9999000';
$conf['max_width'] = '1024';
$conf['max_height'] = '768';
$conf['overwrite'] = TRUE;
$this->load->library('upload');
foreach ($_FILES as $fieldname => $fileObject){
$this->upload->initialize($conf);
if (!empty($fileObject['name'])){
if (!$this->upload->do_upload($fieldname)){
$error = $this->upload->display_errors();
print_r($error);
}else{
print_r("done");
}
}else {
print_r("no");
}
}
Run Code Online (Sandbox Code Playgroud)
视图
<div class="form-group col-md-12">
<label for="Attach"><strong>Add Attachment</strong><br></label>
<input type="file" class="btn btn-default btn-file" name="atta[]" id="Attach" multiple="multiple">
</div>
Run Code Online (Sandbox Code Playgroud) You did not select a file to upload.尽管我选择了要上传的文件,但在尝试上传文件时收到错误消息。我正在使用使用引导程序样式的输入文件。这是问题吗?我按照Codeigniter用户指南中的说明进行文件上传。谁能帮助我,并确定我的代码中的错误?
谢谢
控制者
public function create()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
echo "Upload failed";
}
else
{
$data = array('upload_data' => $this->upload->data());
}
$data = array(
'category' => $this->input->post('category');
'name' => $this->input->post('recipename'),
'ingredients' => $this->input->post('ingredients'),
'directions' => $this->input->post('directions'),
'date' => date("Y/m/d")
);
$this->model->insert($data);
redirect('', 'refresh');
}
Run Code Online (Sandbox Code Playgroud)
视图
<form action="<?php echo base_url();?>home/create" method="POST" role="form" multipart>
<legend>New Recipe</legend>
<div class="form-group">
<label for="">Category</label>
<select name="category" id="input" …Run Code Online (Sandbox Code Playgroud)