简体   繁体   English

图像上传在CodeIgniter中不起作用

[英]image uploading is not working in CodeIgniter

when I click button then it will return error "You did not select a file to upload." 当我单击按钮时,它将返回错误“您没有选择要上传的文件”。 and My image is not uploaded! 并且我的图片没有上传! now please help me what can I do? 现在请帮我该怎么办?

my view is 我的看法是

<form action="insertform" enctype="multipart" name="form" method="post" id="contact-form" class="form-horizontal">
<div class="control-group">
        <label class="control-label" for="name">Image Upload:</label>
        <div class="controls">
              <input type="file" class="input-large" name="image" id="image">
        </div>
 <form>

my controller is: 我的控制器是:

public function upload()
{
    $this->load->helper(array('form', 'url'));

    $config['upload_path'] = FCPATH."upload";
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

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

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('xyz', $error);
    } else {

        $data = array('upload_data' => $this->upload->data());

        $this->load->view('xyz', $data);
    }

}

我认为文件输入名称应该是“ userfile”,而不是“ image”。

CI file upload file control default name is userfile . CI文件上载文件控件的默认名称为userfile

If you want to change the it's name to customized one, then you have to pass the new name to upload function like : 如果要将其名称更改为自定义名称,则必须传递新名​​称以上传功能,例如:

  if ( ! $this->upload->do_upload("image")) // image is your new name for file control

Firstly, 首先,

either change the do_upload function call to: 可以将do_upload函数调用更改为:

if ( ! $this->upload->do_upload('image'))

OR 要么

change the input name to this: 将输入名称更改为此:

<input type="file" class="input-large" name="userfile" id="image">

Secondly, 其次,

change your form enctype to: 将您的表单enctype更改为:

enctype="multipart/form-data"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM