无法在Codeigniter中上传图片

时间:2016-04-14 12:39:01

标签: image file upload codeigniter-3

我在 Codeigniter 中上传图片时出现问题,当我添加新图片时显示错误(您没有选择要上传的文件。)我不知道是否遗漏了我的代码中的内容< / p>

这是我的功能控制器:

public function upload_img(){

        $this->load->model('esthetique_model');
        $config['upload_path'] = realpath(APPPATH.'../upload');
        $config['allowed_types'] = 'jpg|jpeg|png|gif';
        $config['max_size'] = '204800';
        $this->load->library('upload', $config);


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

            $error = array('error' => $this->upload->display_errors());
            foreach ($error as $item => $value){
                echo'<ol class="alert alert-danger"><li>'.$value.'</ol></li>';
            }
            exit;

        }else{

            $upload_data = $this->upload->data();   
            $path =  $upload_data['file_name'];
            $this->esthetique_model->photo_insert_mdl($path);
            echo'<h4 style="color:green">Image uploaded Succesfully</h4>';

        }

    }

我的观点:

<?php echo form_open('esthetique/upload_img'); ?>



                <div class="modal-body">

                        <!-- hidden input montinned with class sr-only -->
                      <div class="form-group"><label class="sr-only" =""></label>
                        <input type="text"  name="idsc" class="sr-only" id="idsc"   ></div>
                          <div class="row">
                            <div class="col-md-6">
                              <div class="form-group">
                                <label for="userfile">Choisissez l'image</label>
                                <input type="file" name="userfile" id="userfile">
                              </div>
                            </div>
                            <div class="form-group">
                                  <img id="loader" src="<?php echo base_url() ?>asset/images/486.GIF" style="height: 30px;">
                            </div>
                            <div class="form-group">
                                  <img id="preview" src="#" style="height: 80px;border: 1px solid #DDC; " />
                            </div>
                          </div>


                      <div class="form-group ">
                        <div class="input-group">
                         <div class="input-group-addon">
                          <i class="fa fa-calendar">
                          </i>
                         </div>
                         <input class="form-control" id="date" name="date" placeholder="Date" type="text"/>
                        </div>
                      </div>

                      <div class="form-group">
                        <textarea class="form-control" row="3" id="note" name="note" placeholder="Note"></textarea> 
                      </div>

                 </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                      <button type="submit" class="btn btn-primary">Enregistrer</button>
                    </div>
                <?php echo form_close(); ?>
              </div>
            </div>
          </div>

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

Try the following (specifying the file input name in your controller):

...

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

...

More information that may be useful: http://www.codeigniter.com/user_guide/libraries/file_uploading.html

答案 1 :(得分:0)

我已经改变了视野

NSDictionary

通过

sharedDateFormatters

现在的工作