您没有 select 文件到 upload.But 图片已上传

You Did not select a file to upload.But the image is uploaded

我发现很多问题都出现了同样的错误。但是这些答案并没有清除我的错误,错误仍然存​​在

当我尝试上传图片时。这个错误出现

" You Did not select a file to upload "

但是 图像上传到正确的位置 ..

控制器

class image extends CI_Controller {

  function __construct() {
    parent::__construct();

    $this->load->helper(array('form', 'url'));

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

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

    $this->load->model('admin_m');

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

  }

  function projects_more() {

    $config['upload_path'] = './uploads/';

    $config['allowed_types'] = 'gif|jpg|png';

    $config['max_size'] = '100000';

    $config['max_width'] = '102400';

    $config['max_height'] = '76800';


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

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

    if (!$this->upload->do_upload('photo')) {

        $error = array('error' => $this->upload->display_errors());

        $this->layout->view('home_page', $error);

    } else {

        $data   = array('upload_data' => $this->upload->data());
        $data1  = $this->upload->data();
        $image  = $data1['file_name'];
        $project  = $this->input->post('project');


        $content= $this->input->post('content');

        $this->admin_m->projects_more($image,$project,$content);
        redirect('image/projects_more');

    }
  }
}

我的浏览页

projects1.php

<?php echo form_open_multipart('image/projects_more'); ?>

<table>

<tr>

<td><input type="file" name="photo" id="photo" size="20"></td>

</tr>

</table>

<input type="submit" name="submit" value="Submit">

<?php echo form_close(); ?>

试试这个:

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

$config =   array
(
'upload_path'   =>  'yourUploadPath',
'allowed_types' =>  'png|jpg|gif',
);
$this -> upload -> initialize($config);
$this -> upload -> do_upload('photo');

如果您想将文件上传到 uploads 文件夹,该文件夹与 applicationsystem 文件夹位于同一文件夹中,您的上传路径应该是这样的:

'upload_path'   =>  'uploads',

顺便说一句,您不需要逐页加载库和助手,您可以使用 application/config 文件夹下的 autoload.php 文件。

对不起。这是我的错误。函数 projects_more 第一次上传图像,在函数结束时我重定向到没有文件要上传的相同函数。第一次上传图片,第二次没有..抱歉浪费你的时间。谢谢 Deniz B.

现在我重定向到显示视图页面的索引函数 select 下一张图片及其详细信息..