$ this-> upload-> do_upload('userfile')无法正常工作

My upload_form.php script

    <html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <!--<form action="" method="post">-->

            <?php echo $error; ?>

            <?php echo form_open_multipart('upload/do_upload');?>
            <input type="file" name="userfile" size="20" />
            <br><br>

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

       <?php 
       form_close();
       ?>

</body>

Upload.php inside controller

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Upload extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->helper(['form', 'url']);
    }

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

    public function do_upload()
    {
        $config = [
            'upload_path'   => './uploads/',
            'allowed_types' => 'gif|jpg|png',
            'max_size'      => 100,
            'max_width'     => 1024, //Mainly goes with images only
            'max_heigth'    => 768,
        ];

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

        if (!$this->upload->do_upload('userfile')) {
            $error = ['error' => $this->upload->display_errors()];
            $this->load->view('upload_form', $error);
        } else {
            $data = ['upload_data' => $this->upload->data()];
            $this->load->view('upload_success', $data);
        }
    }
}

When no file select it gives proper error. But on selecting other file (text or image) no error given. Only display blank page

move uploaded file is working.

Upload Success

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

<h3>Your file was successfully uploaded!</h3>

<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>

<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>

</body>
</html>

try as below..

 public function do_upload()
{
    $config = [
        'upload_path'   => './uploads/',
        'allowed_types' => 'gif|jpg|png',
        'max_size'      => 100,
        'max_width'     => 1024, //Mainly goes with images only
        'max_heigth'    => 768,
    ];

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

    if (!$this->upload->do_upload('userfile')) {
        $error = ['error' => $this->upload->display_errors()];
        $this->load->view('upload_form', $error);
    } else {
          $data = array('upload_data' => $this->upload->data());
          $this->load->view('upload_success', $data);
    }
}

}

Check this code out

if ($_FILES['inputname']['name'] != "") { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '10000'; $this->load->library('upload', $config); }

I have faced same issue but when I changed code from

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

to

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

Then my code working fine. Try once It may be helpful for you. Thank you.