codeigniter中的多个图像上载错误

codeigniter中的多个图像上载错误,codeigniter,Codeigniter,我试图在PHP CodeIgniter中上载多个图像,但它显示了一条错误消息,如下所示 错误消息:isset中的偏移量类型非法或为空 文件名:libraries/Upload.php 行号:148 您没有选择要上载的文件 我的视图文件 <html> <head> <title>Upload Form</title> </head> <body> <?php if(iss

我试图在PHP CodeIgniter中上载多个图像,但它显示了一条错误消息,如下所示

错误消息:isset中的偏移量类型非法或为空
文件名:libraries/Upload.php
行号:148
您没有选择要上载的文件

我的视图文件

<html>
    <head>
    <title>Upload Form</title>
    </head>
    <body>

    <?php
    if(isset($error))
    {
     echo $error;
    }
    ?>

    <?php echo form_open_multipart('upload/do_upload');?>

    <input type="file" name="userfile" size="20" />
    <input type="file" name="userfile1" size="20" />

    <br /><br />

    <input type="submit" value="upload" />

    </form>



    <?php 

    if(isset($upload_data))
    {
        echo "<ul>";

    foreach ($upload_data as $item => $value):

    echo"<li>";

     echo $item . $value;

     echo" </li>";

     endforeach;

    echo "</ul>";
    }
    ?>

    </body>
</html>

上传表单


我的控制器文件

<?php

class Upload extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }

    function index()
    {
        $this->load->view('upload_form', array('error' => ' ' ));
    }

    function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '10000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $this->load->library('upload', $config);

        $fname= array('f1' => 'userfile','f2'=>'userfile' );

        if ( ! $this->upload->do_upload($fname))
        {
            $error = array('error' => $this->upload->display_errors());

            $this->load->view('upload_form', $error);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('upload_form', $data);
        }
    }
}
?>


请帮助我解决问题。

因此,为了在同一请求中执行多个上载,您可以使用类似以下内容更改CodeIgniter查看传入上载文件的方式:

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width']  = '1024';
$config['max_height']  = '768';

$this->load->library('upload');

$errors = [];
$files = $_FILES;
$upload_count = count( $_FILES['userfile']['name'] );
for( $i = 0; $i < $upload_count; $i++ )
{
    $_FILES['userfile'] = [
        'name'     => $files['userfile']['name'][$i],
        'type'     => $files['userfile']['type'][$i],
        'tmp_name' => $files['userfile']['tmp_name'][$i],
        'error'    => $files['userfile']['error'][$i],
        'size'     => $files['userfile']['size'][$i]
    ];

    $this->upload->initialize( $config );

    // Use upload library for file validation
    if( $this->upload->do_upload() )
    {
        // Upload was successful, do something ...
    }
    else
    {
        // Error: Upload Failed
        $errors[] = $this->upload->display_errors('','');
    }
}
$config['upload_path']='./uploads/';
$config['allowed_types']='gif | jpg | png';
$config['max_size']='10000';
$config['max_width']='1024';
$config['max_height']='768';
$this->load->library('upload');
$errors=[];
$files=$\u文件;
$upload_count=count($_FILES['userfile']['name']);
对于($i=0;$i<$upload\u count;$i++)
{
$\u文件['userfile']=[
'name'=>$files['userfile']['name'][$i],
'type'=>$files['userfile']['type'][$i],
'tmp_name'=>$files['userfile']['tmp_name'][$i],
'error'=>$files['userfile']['error'][$i],
'size'=>$files['userfile']['size'][$i]
];
$this->upload->initialize($config);
//使用上载库进行文件验证
如果($this->upload->do_upload())
{
//上传成功,请做些什么。。。
}
其他的
{
//错误:上载失败
$errors[]=$this->upload->display_errors(“”,”);
}
}

这也意味着您将HTML中文件输入的名称更改为userfile[]。

因此,为了在同一请求中进行多次上载,您可以使用类似以下内容更改CodeIgniter查看传入上载文件的方式:

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width']  = '1024';
$config['max_height']  = '768';

$this->load->library('upload');

$errors = [];
$files = $_FILES;
$upload_count = count( $_FILES['userfile']['name'] );
for( $i = 0; $i < $upload_count; $i++ )
{
    $_FILES['userfile'] = [
        'name'     => $files['userfile']['name'][$i],
        'type'     => $files['userfile']['type'][$i],
        'tmp_name' => $files['userfile']['tmp_name'][$i],
        'error'    => $files['userfile']['error'][$i],
        'size'     => $files['userfile']['size'][$i]
    ];

    $this->upload->initialize( $config );

    // Use upload library for file validation
    if( $this->upload->do_upload() )
    {
        // Upload was successful, do something ...
    }
    else
    {
        // Error: Upload Failed
        $errors[] = $this->upload->display_errors('','');
    }
}
$config['upload_path']='./uploads/';
$config['allowed_types']='gif | jpg | png';
$config['max_size']='10000';
$config['max_width']='1024';
$config['max_height']='768';
$this->load->library('upload');
$errors=[];
$files=$\u文件;
$upload_count=count($_FILES['userfile']['name']);
对于($i=0;$i<$upload\u count;$i++)
{
$\u文件['userfile']=[
'name'=>$files['userfile']['name'][$i],
'type'=>$files['userfile']['type'][$i],
'tmp_name'=>$files['userfile']['tmp_name'][$i],
'error'=>$files['userfile']['error'][$i],
'size'=>$files['userfile']['size'][$i]
];
$this->upload->initialize($config);
//使用上载库进行文件验证
如果($this->upload->do_upload())
{
//上传成功,请做些什么。。。
}
其他的
{
//错误:上载失败
$errors[]=$this->upload->display_errors(“”,”);
}
}

这也意味着您将HTML中文件输入的名称更改为userfile[].

我已尝试重新编辑我的问题,但它不是后期编辑的,因此了解may提问并帮助我您必须循环通过$\u文件以在CodeIgniterm中进行多次上载。我是如何执行的请给我解决方案我无法理解我已尝试重新编辑我的问题,但它不是后期编辑的,因此了解may提问并帮助我me您必须循环通过$\u文件在CodeIgnitermins中进行多次上载我是如何执行的请给我我无法理解的解决方案